Hansi
Topic Author
Posts: 12
Joined: 24 May 2017, 11:30

Can't get XAML Storyboard by x:Key, have to add x:Name manually

01 Jun 2017, 13:48

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!
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Can't get XAML Storyboard by x:Key, have to add x:Name manually

01 Jun 2017, 16:40

I guess you are defining the Storyboard as a resource, something like this:
<Grid x:Name="LayoutRoot">
  <Grid.Resources>
    <Storyboard x:Key="anim".../>
  </Grid.Resources>
  ...
</Grid>
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):
var anim = (Storyboard)element.FindResource("anim");
var anim = (Storyboard)layoutRoot.Resources["anim"];
 
Hansi
Topic Author
Posts: 12
Joined: 24 May 2017, 11:30

Re: Can't get XAML Storyboard by x:Key, have to add x:Name manually

02 Jun 2017, 13:03

Oh nice, didn't think of that.
Thank you so much!
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Can't get XAML Storyboard by x:Key, have to add x:Name manually

05 Jun 2017, 16:29

Marked this as solved.

Who is online

Users browsing this forum: No registered users and 1 guest