KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I have a storyboard which targets an element, and binds one of its own properties to a property on another element: <Storyboard> <DoubleAnimation Storyboard.TargetProperty="RenderTransform.X" From="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualWidth}" To="0" Duration="0:0:5"/> </Storyboard> This storyboard works when the storyboard is stored in the resources of the window which holds the storyboard target. The 'From' value is correctly bound to the ActualWidth of the host Window instance. However, I need to store the storyboard in my application level resources. From here, the storyboard does not seem to be able to target the window to determine the 'From' property. This is understandable as from inside <Application.Resources> , the binding won't be able to find an 'ancestor' of type Window. I guess I need to be able to bind the 'From' value, relative to the target of the animation, rather than relative to the storyboard's DoubleAnimation . Is this possible, and if so, how? Here is the sample MainWindow.xaml: <Window.Resources> <!--This works : Storyboard correctly sets 'From' property to 'ActualWidth' of window--> <Storyboard x:Key="localStoryBoard"> <DoubleAnimation Storyboard.TargetProperty="RenderTransform.X" From="{Binding RelativeSource={RelativeSource AncestorType={x:Type Window}}, Path=ActualWidth}" To="0" Duration="0:0:5"/> </Storyboard> </Window.Resources> <StackPanel> <Button RenderTransformOrigin="0,1" HorizontalAlignment="Left" Content="Click me"> <Button.RenderTransform> <TranslateTransform/> </Button.RenderTransf
Tags (comma-separated)
Save Edits
Cancel