2009-09-07 34 views

回答

9

使用的DataTemplates到視圖模型映射到的意見:

<ItemsControl ItemsSource="{Binding SomeCollectionOfViewModels}"> 
    <ItemsControl.Resources> 
     <DataTemplate DataType="{x:Type local:FirstViewModel}"> 
      <Label>Foo</Label> 
     </DataTemplate> 

     <DataTemplate DataType="{x:Type local:SecondViewModel}"> 
      <Label>Bar</Label> 
     </DataTemplate> 
    </ItemsControl.Resources> 
</ItemsControl> 
1

如果我明白你有一個包含兩種不同類型的對象的集合,你想要2個不同的模板。 您可以爲每個對象類型構建一個數據模板,並讓WPF根據對象類型呈現正確的模板。

相關問題