Ian
Ian

Reputation: 4919

Merged dictionaries

One more easy one.

Resources.xaml contains:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<DataTemplate DataType="TestInstanceViewModel"  x:Name="TestInstanceViewModelTemplate">
    <StackPanel Orientation="Vertical">
        <Button Command="{Binding Path=StartCommand}" Content="Start"/>
        <Button Command="{Binding Path=StopCommand}" Content="Stop"/>
        <TextBlock Text="{Binding Path=Status}"/>
    </StackPanel>
</DataTemplate>

Window contains:

<Window x:Class="TestClientMainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Title="Testing client" Height="350" Width="525"
    DataContext="{StaticResource ResourceKey=TheViewModel}" Background="#FFD4BFBF">
<Window.Resources>
    <ResourceDictionary>
    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="Resources.xaml"/>
    </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</Window.Resources>
<Grid>
    <StackPanel HorizontalAlignment="Stretch" Name="stackPanel1" VerticalAlignment="Stretch">
        <ToolBar Height="26" Name="toolBar1">
            <ItemsControl>
                <Button Command="{Binding Path=CreateNewTestCommand}">Add new Test</Button>
            </ItemsControl>
        </ToolBar>
        <ListBox  ItemsSource="{Binding Path=TestInstances}" ItemTemplate="{StaticResource TestInstanceViewModelTemplate}" Name="listBox1" VerticalAlignment="Stretch" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" MinHeight="{Binding ElementName=stackPanel1, Path=Height}" Height="274" />
    </StackPanel>
</Grid>

Then there's a list box where I try:

ItemTemplate="{StaticResource TestInstanceViewModelTemplate}"

This doesn't work. What's the logic behind accessing the resource which I've added to the merged dictionaries?

Thanks

Edited:

Upvotes: 0

Views: 325

Answers (1)

devdigital
devdigital

Reputation: 34369

Try <DataTemplate DataType="TestInstanceViewModel" x:Key="TestInstanceViewModelTemplate">

Upvotes: 3

Related Questions