【问题标题】:Gradient Border on Outer Edges of DataGridHeaderDataGridHeader 外边缘的渐变边框
【发布时间】:2013-08-19 07:04:21
【问题描述】:

见下图……

这是截取自使用 QT 在 c++ 中创建的应用程序的屏幕截图。我需要通过将渐变边框添加到我的 DataGrid 标题的外部垂直边缘来创建类似的外观,并且我没有看到允许我完成此操作的 DataGrid 的属性。使用下面的 DataGridColumnHeader 样式,我已经获得了减去外边缘边框后的外观。如何仅将这些边框添加到标题的外部?

<Style TargetType="{x:Type DataGridColumnHeader}">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="DataGridColumnHeader">
                <Border BorderBrush="{StaticResource ContentPanelHeaderBackgroundBrush}" 
                        BorderThickness="0,1,0,0"
                        CornerRadius="2,2,0,0">
                    <DockPanel Background="{StaticResource ContentPanelHeaderBackgroundBrush}" Width="auto">
                        <Border BorderThickness="0,1,0,0" DockPanel.Dock="Bottom" BorderBrush ="{StaticResource ContentPanelBottomBorderBrush}" />
                            <Grid Height="22">
                                <Grid.ColumnDefinitions>
                                     <ColumnDefinition Width="*" />
                                     <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <ContentPresenter VerticalAlignment="center" Margin="4" />
                            </Grid>
                    </DockPanel>
                </Border>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="Padding" Value="4,0,4,0" />
    <Setter Property="Foreground" Value="{StaticResource FontActiveBrush}" />
    <Setter Property="FontFamily" Value="{StaticResource MainFont}" />
    <Setter Property="FontSize" Value="11" />
    <Setter Property="SnapsToDevicePixels" Value="True" />
    <Setter Property="HorizontalContentAlignment" Value="Left" />
    <Setter Property="MinWidth" Value="0" />
    <Setter Property="Height" Value="22" />
    <Setter Property="Cursor" Value="Hand" />
</Style>

【问题讨论】:

    标签: wpf xaml datagrid styles


    【解决方案1】:

    我建议使用像 Snoop 这样的工具在运行时检查 XAML 树。在我看来,树中某处呈现了一个附加项目,应用了其默认模板。由于您似乎没有覆盖树中的所有默认模板,我想您会以这种方式找到正确的元素(只需寻找背景或边框为黑色的项目)。

    您可以在此处找到该工具:http://snoopwpf.codeplex.com/

    【讨论】:

    • 感谢您的回复。该工具看起来非常有用。我更新了我的问题以澄清我需要什么,因为图像是我需要在 WPF 中模拟的现有应用程序的屏幕截图。
    猜你喜欢
    • 2011-02-12
    • 1970-01-01
    • 1970-01-01
    • 2021-03-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多