WPF 数据网格中的列标题样式问题

发布于 2024-07-20 06:57:14 字数 2422 浏览 5 评论 0原文

我已经格式化了 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

沙沙粒小 2024-07-27 06:57:14

您好,我刚刚发现这篇文章存在同样的问题,并且能够通过将宽度设置为标题的确切宽度(样式停止的位置)来为我修复它。

在您的环境中,它可能不适合您。 另请注意,这是几个月前的:-)

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 :-)

终遇你 2024-07-27 06:57:14

我以前遇到过同样的问题,更新到最新版本的网格(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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文