black eyed pea
black eyed pea

Reputation: 427

WPF: the right way to reuse resources in wpf

I have some storyboards defined in a <Window.Resources> tag in Xaml, and I wanna use them on a number of UIElement objects, so I think somehow I have to keep resetting the storyboard everything I retrieve it since it may have been used before, what's the right way to do this? Do I call MyStoryBoard.clone() everything I pull it out from the resources? Or should I call MyStoryBoard.GetAsFrozen()? Is there a better way to do this? What's the standard practice?

Upvotes: 0

Views: 508

Answers (1)

mathieu
mathieu

Reputation: 31202

You can set the x:Shared attribute to false, to prevent your resource being reused. This will create a new instance for each call of {StaticResource MyStoryBoard}.

<StoryBoard x:Key="MyStoryBoard" x:Shared="False" />

Upvotes: 4

Related Questions