Data Binding – Resource dictionaries with bindings

  • Need to have a class
  • Need to have a code behind
  • Need to be loaded using their type

XAML

<ResourceDictionary

x:Class=“xBindSample.MyTemplates“

xmnls:model=“using:xBindSampleModel“>

<DataTemplate x:Key=“FullNameTemplateInRDFile“ x:DataType=“model:IEmployee“>

<TextBlock Text=“{x:Bind name}“ />

</DataTemplate>

</ResourceDictionary>

C#

namspace xBindSample

{

public  parital class MyTemplates

{

public MyTemplates()

{

InitializeComponent();

}

}

}

Markup

<UserControl.Resources>

<ResourceDictionary>

<Style TargetType=“Button“ x:Key=MyButtonStyle“>

</Style>

<ResourceDictionary.MergedDictionaries>

<local:MyTemplates/>

<ResorceDictionary Source=“filename“ />

</ResourceDictionary.MergedDictionaries>

</ResourceDictionary>

</UserControl.Resources>