I would like to move a StackPanel horizontally when the user clicks a button. I'm implementing DoubleAnimation with TargetName and TargetProperty. But, I don't know which TargetProperty to use.
Can anyone help me?
If you put the StackPanel inside a Canvas you can achieve this behavior by setting the Canvas.X and Canvas.Y properties. Alternatively you could animate the Margin of the StackPanel by using ThicknessAnimation. Check out this post for a similar request.
Another method would be a TranslateTransform applied to the RenderTransform of the StackPanel. The TargetProperty path for the animation then would be RenderTransform.X.
Related
I have an ItemsControl that host some input controls (textboxes, etc). When I click in the background of the ItemsControl, the focus is automatically changed to the first item in the ItemsControl.
Is there a way to prevent this? I already tried overriding OnGotFocus on the ItemsControl without calling base but it did not worked.
Thanks in advanced!
Jacques.
Ok, I figured out what was causing the first element to get the focus. In my case, I am using a ScrollViewer hosting a custom ItemsControl. The ItemsControl and container inside of it have IsTabStop set to false. The change of focus is made by the ScrollViewer in the OnMouseLeftButtonDown method.
Since the ScrollViewer is sealed, I had to override the OnMouseLeftButtonDown on my container and ItemsControl to set e.Handled to true. This solved my issue.
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
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.
I have some controls added in a stackpanel programmatically. What i want to do is that i want one of the controls in this stackpanel to be placed over another control. Specifically, I want to place button over an image in this stack panel. I couldn't find zindex property in c# codebehind. Although it seems very simple problem but i am unable to find any clue to solve this problem. Anyone please......??
Try placing all your controls on Canvas. Then you can set Zindex with:
this.controlName.SetValue(Canvas.ZIndexProperty, 10d);
Only the Canvas panel supports a ZIndex property. Stackpanel doesn't because each item is placed one after the other in the panel so they shouldn't overlap each other. This can be a little annoying at times when you have animated transforms moving the items about because the previous assumption isn't actually true.
In general though if you need to place items in a visual stack the Stackpanel isn't the right place for it. Perhaps a Canvas or you could use a Grid where the oridinal position of a element determines its "zorder" in a cell.
From xaml:
<StackPanel Canvas.ZIndex="1">
</StackPanel>
Does anyone have any ideas on how I can remove the focus rectangle from a silverlight textbox? (I'm talking about the blue rectangle that appears when you click on the texblock to start typing)
I'm looking through the default style and template for the textbox but can't seem to figure out which element to tweak.
Thanks!
In the template you will find a border called FocusVisualElement. In the base and Unfocused Visual State it has an opacity of 0%. In the focused Visual state it has 100% opacity. You can simply delete the FocusVisualElement if you don't want any border indicating the focus.
This probably looks weird when the MouseOverBorder still appears so you might want to delete that too from the Template, however move the ContentElement it holds to the parent Grid first.
Alternatively you could set the Opacity to 0% for these borders in all states.