1
我正在建立一個DataGrid,我想根據當前項目的基礎數據類型在單元格內切換圖像。WPF DataGrid:通過項目的DataType選擇CellTemplateSoure
問題: 是否可以應用這種類型的模板切換? 最好只在xaml中?
的ItemsSource是
ObservableCollection<BaseModel>
包含類型
IncidentModel : BaseModel
ServiceModel : BaseModel
的項目這是我目前:
<DataGrid
ItemsSource="{Binding TicketCollection,UpdateSourceTrigger=PropertyChanged,Mode=OneWay}"
IsReadOnly="True"
AutoGenerateColumns="False"
DockPanel.Dock="Top">
<DataGrid.Resources>
<DataTemplate DataType="{x:Type models:IncidentModel}">
<Image Source="pack://application:,,,/SMLib;component/Files/Images/16x16/Active_16.png" />
</DataTemplate>
<DataTemplate DataType="{x:Type models:ServiceModel}">
<Image Source="pack://application:,,,/SMLib;component/Files/Images/16x16/IncidentMgmt_AllIncidents_16.png" />
</DataTemplate>
</DataGrid.Resources>
<DataGrid.Columns>
<DataGridTemplateColumn Header="Typ">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Id" Binding="{Binding Id,UpdateSourceTrigger=PropertyChanged,Mode=OneWay}" />
<DataGridTextColumn Header="Titel" Binding="{Binding Title,UpdateSourceTrigger=PropertyChanged,Mode=OneWay}" />
<DataGridTextColumn Header="Status" Binding="{Binding Status,UpdateSourceTrigger=PropertyChanged,Mode=OneWay}" />
<DataGridTextColumn Header="Erstellung" Binding="{Binding CreatedDate,UpdateSourceTrigger=PropertyChanged,Mode=OneWay}" />
</DataGrid.Columns>
</DataGrid>
感謝一切可能的幫助!
謝謝!奇蹟般有效! – Daniel