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