ContentControls that reference the same StaticResource display only one resource

I have a resource in a ResourceDictionary:

<Viewbox x:Key="Icons.Profile"> <Canvas Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0"> <Path Width="40.7907" Height="33.55" Canvas.Left="16.2093" Canvas.Top="22.2" Stretch="Fill" Fill="#FFFFFFFF" Data="F1 M ... "/> </Canvas> </Viewbox> 

If I add two Buttons / Content Controls that reference StaticResource, only one processed last seems to display the Icon icon

 <Button Content="{StaticResource Icons.Profile}" /> 

Does anyone know why and how I can get around this? In Visual Studio and Blend, content is displayed for all controls.

+5
source share
1 answer

This is because an element can have only one logical parent, however you can set your resource to x:Shared="false" , and this will create / display a new element for each use.

Example:

 <Viewbox x:Key="Icons.Profile" x:Shared="false"> <Canvas Width="76" Height="76" Clip="F1 M 0,0L 76,0L 76,76L 0,76L 0,0"> <Path Width="40.7907" Height="33.55" Canvas.Left="16.2093" Canvas.Top="22.2" Stretch="Fill" Fill="#FFFFFFFF" Data="F1 M ... "/> </Canvas> </Viewbox> 
+8
source

Source: https://habr.com/ru/post/1200170/


All Articles