Can't get XAML Storyboard by x:Key, have to add x:Name manually
I found out that I can't use FindName() with the x:Key value of a Storyboard created in BLEND.
When I add a x:Name manually, I can use FindName() to access it.
Is there a way to access a Storyboard via x:Key? BLEND denotes it as "Name", but in the file it's x:Key.
So I'm forced to edit the XAML by hand and add x:Name.
I guess that's not the way it's supposed to be...
Thanks!
When I add a x:Name manually, I can use FindName() to access it.
Is there a way to access a Storyboard via x:Key? BLEND denotes it as "Name", but in the file it's x:Key.
So I'm forced to edit the XAML by hand and add x:Name.
I guess that's not the way it's supposed to be...
Thanks!
-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: Can't get XAML Storyboard by x:Key, have to add x:Name manually
I guess you are defining the Storyboard as a resource, something like this:
In this case the correct way to access the storyboard is by using the FindResource method (on any element in the UI tree), or directly looking into the resources property (of the layout root element):
Code: Select all
<Grid x:Name="LayoutRoot">
<Grid.Resources>
<Storyboard x:Key="anim".../>
</Grid.Resources>
...
</Grid>
Code: Select all
var anim = (Storyboard)element.FindResource("anim");
Code: Select all
var anim = (Storyboard)layoutRoot.Resources["anim"];
Re: Can't get XAML Storyboard by x:Key, have to add x:Name manually
Oh nice, didn't think of that.
Thank you so much!
Thank you so much!
-
-
sfernandez
Site Admin
- Posts: 2062
- Joined:
Re: Can't get XAML Storyboard by x:Key, have to add x:Name manually
Marked this as solved.
Who is online
Users browsing this forum: No registered users and 0 guests