我正在尝试合并或格式化数据网格WPF中的标头。
示例:
|收到|发送|收到|发送|
实现这一目标的最简单方法是什么。
三江源
答案 0 :(得分:0)
你可以建立这样的东西:
<DataGrid>
<DataGrid.Columns>
<DataGridTextColumn>
<DataGridTextColumn.HeaderTemplate>
<DataTemplate>
<StackPanel>
<TextBlock Text="Station1" HorizontalAlignment="Center"></TextBlock>
<WrapPanel>
<TextBlock Text="Receive" Margin="2"></TextBlock>
<TextBlock Text="|" Margin="2"></TextBlock>
<TextBlock Text="Send" Margin="2"></TextBlock>
</WrapPanel>
</StackPanel>
</DataTemplate>
</DataGridTextColumn.HeaderTemplate>
</DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
答案 1 :(得分:0)
结束了这样的事情。也许这对你们中的一些人有用,所以我发布了这个
<DataGridTemplateColumn MinWidth="180" >
<DataGridTemplateColumn.Header>
<Grid>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.ColumnSpan="3" HorizontalAlignment="Center" Text="Loc 1"/>
<TextBlock Grid.Column="0" Grid.Row="1" Text="Received" Width="60" TextAlignment="Center"/>
<TextBlock Grid.Column="1" Grid.Row="1" Text="Sent" Width="60" TextAlignment="Center"/>
<TextBlock Grid.Column="2" Grid.Row="1" Text="Defect" Width="60" TextAlignment="Center"/>
</Grid>
</DataGridTemplateColumn.Header>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0" Text="{Binding Path=Loc01_10}" MinWidth="60" TextAlignment="Right" />
<TextBlock Grid.Column="1" Text="{Binding Path=Loc01_20}" MinWidth="60" TextAlignment="Right" />
<TextBlock Grid.Column="2" Text="{Binding Path=Loc01_40}" MinWidth="60" TextAlignment="Right" />
</Grid>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>