I have defined a DataTemplate inside a ResourceDictionary. I need to access the DataTemplate in the code behind. (i.e) I need to set this DataTemplate defined inside a ResourceDictionary to a ContentControl.ContentTemplate property in the code behind. How can i achieve this. Below is the my xaml code.
<ResourceDictionary>
...
<DataTemplate x:Key="template">
<Border BorderThickness="2"
BorderBrush="Black">
<TextBlock Text="{Binding Path=value}" Padding="2" />
</Border>
</DataTemplate>
...
</ResourceDictionary>
This is the code that I tried:
ResourceDictionary rd = new ResourceDictionary() { Source = new Uri("ms-appx:///sample.xaml", UriKind.Absolute) };
object tem;
rd.TryGetValue("template", out tem);
Can anyone point me how to access it?