如何将多个头在WPF数据网格相结合 [英] how to combine multiple header in wpf datagrid
问题描述
我想结合这两个栏目奖金和游戏。
I want to Combine these two column "Stakes" and "Game".
我要两栏合并成使用WPF DataGrid中一列。
I want to combine two column into one column using wpf datagrid.
我的DataGrid的是如下! [在这里输入的形象描述] [2]
![此处输入的形象描述] [3]
My DataGrid is as Follow.![enter image description here][2] ![enter image description here][3]
<DataGrid.CellStyle>
<Style TargetType="{x:Type DataGridCell}">
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Effect">
<Setter.Value>
<DropShadowEffect BlurRadius="0" Color="#FF000000" Direction="-60" Opacity="0.32" ShadowDepth="1"/>
</Setter.Value>
</Setter>
<Setter Property="Margin" Value="10,0,0,0" />
<Setter Property="VerticalContentAlignment" Value="Bottom"/>
</Style>
</DataGrid.CellStyle>
<DataGrid.RowStyle>
<Style TargetType="{x:Type DataGridRow}">
<Setter Property="FontSize" Value="12"/>
<Setter Property="FontFamily" Value="Arial"/>
<Setter Property="Foreground" Value="#404040"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="DataContext">
<Setter.Value>
<TextBlock Margin="10,0,0,0" TextWrapping="Wrap" Text="{Binding}">
<TextBlock.Effect>
<DropShadowEffect BlurRadius="0" Color="#FF000000" Direction="-60" Opacity="0.32" ShadowDepth="1"/>
</TextBlock.Effect>
</TextBlock>
</Setter.Value>
</Setter>
</Style>
</DataGrid.RowStyle>
<DataGrid.RowBackground >
<ImageBrush ImageSource="/ClientApplication;component/Images/second_row_bg.png"/>
</DataGrid.RowBackground>
<DataGrid.AlternatingRowBackground>
<ImageBrush ImageSource="/ClientApplication;component/Images/bonus_progress_bg.png"/>
</DataGrid.AlternatingRowBackground>
<DataGrid.ColumnHeaderStyle>
<Style TargetType="{x:Type DataGridColumnHeader}">
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="ContentTemplate" >
<Setter.Value>
<DataTemplate>
<TextBlock Margin="10,0,0,0" TextWrapping="Wrap" Text="{Binding}">
<TextBlock.Effect>
<DropShadowEffect BlurRadius="0" Color="#FF000000" Direction="-60" Opacity="0.32" ShadowDepth="1"/>
</TextBlock.Effect>
</TextBlock>
</DataTemplate>
</Setter.Value>
</Setter>
<Setter Property="Background">
<Setter.Value>
<ImageBrush ImageSource="/ClientApplication;component/Images/table_bg_header.png"/>
</Setter.Value>
</Setter>
<Setter Property="BorderBrush">
<Setter.Value>
<ImageBrush ImageSource="/ClientApplication;component/Images/titel_bg.png"/>
</Setter.Value>
</Setter>
<Setter Property="Foreground" Value="#404040" />
<Setter Property="BorderThickness" Value="0, 0, 1, 0"/>
<Setter Property="Height" Value="26" />
<Setter Property="FontSize" Value="14"/>
<Setter Property="FontFamily" Value="Arial"/>
</Style>
</DataGrid.ColumnHeaderStyle>
<DataGrid.Columns>
<DataGridTextColumn Width="125" Header="Table" Binding="{Binding Path=Table}">
</DataGridTextColumn>
<DataGridTextColumn Width="102" Header="Stakes" Binding="{Binding Path=Stakes}" />
<DataGridTextColumn Width="95" Header="Game" Binding="{Binding Path=Game}" />
<DataGridTextColumn Width="87" Header="Type" Binding="{Binding Path=Type}" />
<DataGridTextColumn Width="83" Header="Players" Binding="{Binding Path=Players}" />
<DataGridTextColumn Width="117" Header="Average Pot" Binding="{Binding Path=Average}" />
<DataGridTextColumn Width="65" Header="H/Hr" Binding="{Binding Path=hhr}" />
</DataGrid.Columns>
</DataGrid>
请给我这个重要的评论。
感谢您的帮助。
Please give me important comment on this. Thanks For your help.
推荐答案
如果你`重新确定以使其只读,那么最简单的方法就是多了一个属性绑定到 - StakesAndGame
:
If you`re ok with making it read-only, then the easy way is to have one more property to bind to - StakesAndGame
:
public string StakesAndGame
{
get { return string.Format("{0} {1}", Stakes, Game); }
}
和只添加列使用它:
<DataGridTextColumn Width="102" Header="Stakes" Binding="{Binding StakesAndGame}" />
只是不`吨忘记调用 OnPropertyChanged
对于财产所有权以及在木桩或游戏的变化。或者,你可以写一个值转换器和两列与之相结合,但它需要比以前多了一个编码。
Just don`t forget to call OnPropertyChanged
for that property as well when Stakes or Game change. Or you can write a value converter and combine two columns together with it, but it requires more coding than previous one.
如果你需要他们可写,然后it`更难,我真的不`吨推荐这种做法。但是,如果你需要它,无论如何,你可以用 DataGridTemplateColumn
发挥像这个答案
If you need them to be writable, then it`s harder and I really don`t recommend such approach. But if you need it anyway, you could play with DataGridTemplateColumn
like in this answer.
这篇关于如何将多个头在WPF数据网格相结合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!