views:

67

answers:

1
A: 

Not sure I follow entirely, but presumably there are a fixed number of fields that can be displayed. Thus, you could expose these fields via your view model:

public class YourViewModel : ViewModel
{
    public string Text
    {
        //get and set omitted
    }

    public ImageSource Image1
    {
        //get and set omitted
    }

    public ImageSource Image2
    {
        //get and set omitted
    }
}

Each template you have could be stored under a different key:

<DataTemplate x:Key="FirstTemplate" DataType="{x:Type local:YourViewModel}">
    ...
</DataTemplate>

<DataTemplate x:Key="SecondTemplate" DataType="{x:Type local:YourViewModel}">
    ...
</DataTemplate>

Then within each template can just bind to the fields in your view model:

<TextBlock Content="{Binding Text}"/>
<Image Grid.Row="1" Source="{Binding Image1}"/>
<Image Grid.Row="1" Grid.Column="1" Source="{Binding Image2}"/>

To switch between templates, you can just substitute the resource at the appropriate level of your resource hierarchy:

this.Resources.Clear();
this.Resources.Add(FindResource(templateKey));

HTH, Kent

Kent Boogaart