2011-03-09 150 views
0

更容易一個。合併字典

Resources.xaml包含:

<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 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> 

然後有一個列表框,我嘗試:

ItemTemplate="{StaticResource TestInstanceViewModelTemplate}" 

這不起作用。訪問已添加到合併字典的資源後面的邏輯是什麼?

感謝

編輯:

回答

3

嘗試<DataTemplate DataType="TestInstanceViewModel" x:Key="TestInstanceViewModelTemplate">

+0

完美的,你看我已經不再想着今天,感謝在充盈會在發佈前從事大腦更:) – Ian

+0

這是正確的? x:鍵而不是x:名稱。你不是第一個相信我的人。 –

+0

這是那些日子之一:) – Ian