【发布时间】:2011-11-03 15:24:27
【问题描述】:
我有以下 xaml 代码。
<tk:DataGrid
ItemsSource="{Binding Path=Products}"
AutoGenerateColumns="False">
<tk:DataGrid.Columns>
<tk:DataGridTextColumn
Header="Id">
<tk:DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type tk:DataGridCell}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Margin="0,10" Text="{Binding Path=Id}" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</tk:DataGridTextColumn.CellStyle>
</tk:DataGridTextColumn>
<tk:DataGridTextColumn
Header="Product">
<tk:DataGridTextColumn.CellStyle>
<Style TargetType="{x:Type tk:DataGridCell}">
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Margin="0,10" Text="{Binding Path=Name}" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</tk:DataGridTextColumn.CellStyle>
</tk:DataGridTextColumn>
</tk:DataGrid.Columns>
</tk:DataGrid>
如何摆脱复制粘贴?将其移动到资源的直接方法失败了,因为 Text="{Binding Path=XYZ}" 停止工作。
【问题讨论】: