Artem Makarov
Artem Makarov

Reputation: 874

Take element from Resources more than once in XAML

I have some elements of type Path in XAML UserControl resources, when I try to use some element more than once (for example in two different StackPanels) I get an InvalidOperationException.

What's the problem? Why resource element identifies as real component on my control?

Upvotes: 0

Views: 199

Answers (1)

Rick Sladkey
Rick Sladkey

Reputation: 34240

Only Freezable objects that are frozen can be used more than once in the same visual tree. Path objects are not Freezable objects but FrameworkElement objects, hence the error. You can try using the x:Shared="False" attribute on the Path resource to create a new copy each time the resource is accessed to prevent the exception.

Upvotes: 3

Related Questions