Clone ResourceDictionary Object

styles, wpf, xaml

Solution

You can use the x:Shared attribute to do this, e.g.:

<Grid x:Key"FooGrid" x:Shared="False"> 
   <!--Content Here--> 
</Grid> 

Problem

Say that I have the object: ``` <Grid x:Key"FooGrid> <!--Content Here--> </Grid> ``` And I normally reference it by something like: ``` <ContentPresenter Content="{StaticResource ResourceKey=FooGrid}"/> ``` And while this works, if I call it a second time, it removes the first use and moves it to the requested second use. Clearly there's an issue of my method of calling the resource. What would be a better way of going about this, if I want a unique instance of the object, similar to what Style can create? I'd use style, but as I understand it Style doesn't support defined content.

Original source