0
我有以下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}”停止工作。
非常感谢! – vkrzv