Take element from Resources more than once in XAML
I have some elements of type Path
in XAML UserControl r开发者_如何学编程esources, when I try to use some element more than once (for example in two different StackPanel
s) I get an InvalidOperationException.
What's the problem? Why resource element identifies as real component on my control?
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.
精彩评论