2011-03-09 13 views
0

もう1つは簡単です。マージされた辞書

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の代わりにkey:nameあなたは私を信頼する最初の人ではありません。 –

+0

それは当時のことの一つです:) – Ian

関連する問題