WPF 数据网格中的列标题样式问题
我已经格式化了 Wcf Toolkit Datagrid,下面是它的 ColumnHeader 样式 但是,列标题中仍然有一些区域的样式与图像中所示的
http: //www.freeimagehosting.net/uploads/9aba4fbd93.jpg
<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type dg:DataGridColumnHeader}">
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Background" Value="Orange" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="dg:DataGridColumnHeader">
<dg:DataGridHeaderBorder
x:Name="headerBorder"
Background="Orange">
<Border BorderThickness="2"
CornerRadius="5"
Background="Orange"
BorderBrush="DarkOrange">
<Grid>
<TextBlock Text="{TemplateBinding Content}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
TextWrapping="Wrap"/>
</Grid>
</Border>
</dg:DataGridHeaderBorder>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<dg:DataGrid Grid.Row="1" Grid.RowSpan="1"
Name="dgQuestion"
HorizontalAlignment="Left"
AutoGenerateColumns="True"
Width="740"
MinWidth="200"
MaxWidth="740"
Background="Wheat"
ColumnHeaderHeight="30"
ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}"
RowStyle="{StaticResource RowStyle}"
CanUserAddRows="False"
CanUserDeleteRows="False"
AlternationCount="2"/>
I have formated the Wcf Toolkit Datagrid and below in the is the ColumnHeader Style for it
But, there are still some area in Column Header, which are not styled as shown in the image
http://www.freeimagehosting.net/uploads/9aba4fbd93.jpg
<Style x:Key="ColumnHeaderStyle" TargetType="{x:Type dg:DataGridColumnHeader}">
<Setter Property="VerticalContentAlignment" Value="Center" />
<Setter Property="Background" Value="Orange" />
<Setter Property="Foreground" Value="White" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="dg:DataGridColumnHeader">
<dg:DataGridHeaderBorder
x:Name="headerBorder"
Background="Orange">
<Border BorderThickness="2"
CornerRadius="5"
Background="Orange"
BorderBrush="DarkOrange">
<Grid>
<TextBlock Text="{TemplateBinding Content}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
TextWrapping="Wrap"/>
</Grid>
</Border>
</dg:DataGridHeaderBorder>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<dg:DataGrid Grid.Row="1" Grid.RowSpan="1"
Name="dgQuestion"
HorizontalAlignment="Left"
AutoGenerateColumns="True"
Width="740"
MinWidth="200"
MaxWidth="740"
Background="Wheat"
ColumnHeaderHeight="30"
ColumnHeaderStyle="{DynamicResource ColumnHeaderStyle}"
RowStyle="{StaticResource RowStyle}"
CanUserAddRows="False"
CanUserDeleteRows="False"
AlternationCount="2"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您好,我刚刚发现这篇文章存在同样的问题,并且能够通过将宽度设置为标题的确切宽度(样式停止的位置)来为我修复它。
在您的环境中,它可能不适合您。 另请注意,这是几个月前的:-)
Hi I just found this post with the same problem and was able to fix it for me, by setting the Width to the exact width of the header (where the styling stops).
It might not work for you in your context. Also notice this is months old :-)
我以前遇到过同样的问题,更新到最新版本的网格(WPFToolkit.dll)似乎已经为我解决了这个问题
I was previously having the same issue, updating to the latest version of the grid (WPFToolkit.dll) appears to have fixed this for me