【发布时间】:2017-11-26 14:16:55
【问题描述】:
我有以下数据模板:
<Window.Resources>
<DataTemplate x:Key="MyDataGridCell_TextBox">
<TextBlock Text="{Binding}" />
</DataTemplate>
</Window.Resources>
以及我的 DataGrid 中的以下 DataGridColumn:
<DataGrid ItemsSource="{Binding Logs}">
<DataGrid.Columns>
<DataGridTemplateColumn Header="A" CellTemplate="{StaticResource MyDataGridCell_TextBox}
HOW_DO_I_SET_HERE_DisplayMember_To_PropA???"/>
<DataGridTemplateColumn Header="B" CellTemplate="{StaticResource MyDataGridCell_TextBox}
HOW_DO_I_SET_HERE_DisplayMember_To_PropB???"/>
</DataGrid.Columns>
</DataGrid>
如何从 DataGridTemplateColumn 设置 DataTemplate 的 DisplayMemberPath?
public class Log
{
public string PropA {get;set;}
public string PropB {get;set;}
}
Logs <=> ObservableCollection<Log>
PS:我删除了不相关的代码部分,如样式、一些道具等,并尽可能地简化代码。
【问题讨论】:
-
您不能在 XAML 中执行此操作。您需要为每列定义一个 DataTemplate。
-
@mm8。请写下来作为答案,以便我接受。
标签: c# .net wpf xaml data-binding