WPF: Disappearing icons

前端 未结 1 780
情话喂你
情话喂你 2021-02-09 07:50

I have several icons which are declared in Window.Resources. They show up fine the first time they need to appear (eg: a Menu is clicked, the MenuItem icon works), but after ano

1条回答
  •  长发绾君心
    2021-02-09 08:46

    That's because your resource is an Image, which is a Control. Controls can only have one parent so it's effectively being re-parented in each MenuItem on the fly.

    Your options are:

    1. Don't use Image and instead use ImageSource or even a string containing the URI of the image.
    2. Set the resource to non-shared with the x:Shared XAML attribute. This will create multiple Image controls as needed.

    0 讨论(0)
提交回复
热议问题