开发者

Take element from Resources more than once in XAML

开发者 https://www.devze.com 2023-02-28 06:56 出处:网络
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 StackPanels) I get an InvalidOperationExce

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 StackPanels) 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.

0

精彩评论

暂无评论...
验证码 换一张
取 消