UserControl Storyboard objects moving out of UserControl - silverlight

I have a UserControl that have a storyboard that moves a control (within my UserControl) out of the usercontrol (using a TranslateX RenderTransform).
When I move the object out of the control it shows on the parent Page (that hosts my UserControl). Is there a way to just hide it when it reaches the boundaries of my UserControl?

At the end of your storyboard set the animated controls visibility to collapsed/opacity = 0. If that animation is too abrupt for you, animate the opacity to 0 as the storyboard progresses. To detect when the animation goes out of your control would be rather difficult. You're probably best off "guessing" by waiting a few tenths of a second.

You could try setting the Canvas.ZIndex so that the Control is behind the Parent Control

The Z-Index doesn't work since its outside my UserControl.
I was thinking more like using the "Clip" property, but I'm not really familiar with it :/

What I finally did :
Use a Canvas (instead of a Grid) as my LayoutRoot of my UserControl
Added a Canvas.Clip that matches the size of my UserControl
On the SizeChanged of my UserControl I resize my Clip to fit the new size.
I'd like to post the XAML here but somehow the CodeSample does not work :/ Sorry

Related

Bind WPF conrol size to window size

I am trying to bind a TabControl to the size of the MainWindow in WPF. I have done it very easily, but the problem is with padding or margin.
If I just set the both with the same size during the window resize, then the TabControl hangs off the right side of the window by it's border. I have tried playing with padding and margin of the TabControl with no effect on it's over flow of the window.
Should I use a custom converter? My skill with them is pretty novice and am not sure how I would work a two way converter for these properties.

GetAdornerLayer() for a control derived from MedialElementBase

I have a WPF control which is derived from MedialElementBase(Base class is UIElement).
This control is used to dislay video from webcam. I need to draw lines on this video.
I am using WPF Adorners and calling GetAdornerLayer() for above control which always
returns NULL. Am I using this correctly? Any idea why this is happening?
An AdornerLayer is created by an AdornerDecorator or a ScrollContentPresenter in the visual tree. By default the ControlTemplate for Window has one surrounding all its content. If there is neither an AdornerDecorator or ScrollContentPresenter as a parent to your control, it will return null.

wpf datagrid FrozenColumnCount and usercontrol with adorner

i have a DataGrid with FrozenColumnCount set to one and some DataTemplateColumns which contains a control which uses an adorner (simply lets say a TextBox with an Adorner which shows the Text "Unit" or somelike). If I use the HorizontalScrollbar the adorner lays before the fixed column. How can I solve this problem.
This is the nature of Adorners, they will always be on "top".
Anything placed in the adorner layer is rendered on top of the rest of
any styles you have set. In other words, adorners are always visually
on top and cannot be overridden using z-order.

Silverlight - Fill a Rectangle (or other controls which have a Brush Property) with a custom UserControl

I need to fill a Rectangle with a custom UserControl. The rectangle's .Fill property accepts a Brush and in Silverlight there is no equivalent for VisualBrush.
I've found this post - http://chriscavanagh.wordpress.com/2009/09/24/silverlight-visualbrush-and-rounded-corners/ - with a possible solution. However this approach requires the UserControl (which will be used to fill the rectangle) to be rendered first outside the rectangle so that the VisualImage can convert it to a WritableBitmapImage.
Does anyone know any alternate solution? I would prefer not having to render the user control outside the rectangle and remove it afterwards, because there is the possibility for some flickrs to occur.
Thanks and best regards,
Bruno
There is no alternate solution if you must be using a rectangle and brush for its fill.
I take it you already have a reason not to simply use a Border containing the UserControl directly? If you don't want the usercontrol to response to the mouse you could include in the Border a Grid containing both your UserControl and a Rectangle with a transparent fill.

Cant Drag ListBoxItem Adorner outside of ListBox in WPF -ScrollViewerProblem

I am working with a WPF application that uses alot of drag and drop. Everything is working fine, with exception of ListBoxItems. I have a ListBox with ListBoxItems that can be dragged to another target( a StackPanel). The problem is, when I drag the cursor outside the ListBox, I cant see the Adorner that I have setup with the ListBoxItem?
I know this is a common problem, but I am just not sure how to fix it. Is there something that I need to do to allow me to drag outside of the ListBox control?
Below I have attached what the UI looks like so far. As you can see, there is a ListBox on the bottom left. When I drag an item, the adorner appears, and follows the cursor around while the cursor is over the ListBox, but if I try to move the cursor away from the listbox, the Adorner seems to almost go under the other controls(zIndex?).
Edit - Solution
I have changed the code to handle the AdornerLayer relative to the window as oppose to relative to the AdornedElement
So I changed
layer = AdornerLayer.GetAdornerLayer(_originalElement);
to
layer = AdornerLayer.GetAdornerLayer(this);
This solved the problem of the ScrollViwer clipping the AdornerLayer
The ListBox (or, to be specific, the ScrollViewer within the listbox) clips any adorners attached to it's children. This is done to ensure that adorners for items scrolled out of view are not shown. To get around this, you need to explicitly put thing in the Window's adorner and not that of the listbox or listboxitem

Resources