我的数据网格在WPF项目中有60列,
我必须为每个列添加以下标记,这会使XAML文件变大 有没有办法概括这个标签?
<DataGridTextColumn.CellStyle>
<Style TargetType="DataGridCell">
<Setter Property="ToolTip" >
<Setter.Value>
<MultiBinding Converter="{StaticResource ToolTipConverter}">
<Binding Path="RowID" />
<Binding Path="BusinessPhone" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</DataGridTextColumn.CellStyle>
答案 0 :(得分:2)
如果要将该样式应用于datagrid中的所有列,请将DataGridCell的样式放在DataGrid的资源中。如果只想将其应用于某些列,请为样式命名并按名称将样式应用于每列。实施例
要应用于所有列:
<DataGrid.Resources>
<Style TargetType="DataGridCell">
<Setter Property="ToolTip" >
<Setter.Value>
<MultiBinding Converter="{StaticResource ToolTipConverter}">
<Binding Path="RowID" />
<Binding Path="BusinessPhone" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
要应用于各列:
<Style TargetType="DataGridCell" x:Key="YourStyleName">
<Setter Property="ToolTip" >
<Setter.Value>
<MultiBinding Converter="{StaticResource ToolTipConverter}">
<Binding Path="RowID" />
<Binding Path="BusinessPhone" />
</MultiBinding>
</Setter.Value>
</Setter>
</Style>
...
<DataGridTextColumn CellStyle="{StaticResource YourStyleName} " >