使用 gridview 的样式

发布于 2024-11-26 18:06:45 字数 3130 浏览 1 评论 0原文

如何在 gridview 中使用以下样式

<Stylex:Key="{x:TypeCustom:DataGridRowHeader}"TargetType="{x:TypeCustom:DataGridRowHeader}">
<SetterProperty="Background"Value="{StaticResource RowHeaderBackgroundBrush}" />     
<SetterProperty="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:TypeCustom:DataGridRowHeader}">
            <Grid>                       
                <Custom:DataGridHeaderBorder IsSelected="{TemplateBinding IsRowSelected}"
                             IsHovered ="{TemplateBinding IsMouseOver}"
                             IsPressed="{TemplateBinding IsPressed}"
                             BorderBrush="{Binding RelativeSource={RelativeSource AncestorType={x:Type Custom:DataGrid}},
                                Path=HorizontalGridLinesBrush}"
                             Background="{TemplateBinding Background}"                                    
                             BorderThickness="0,1,0,0"
                             Padding ="{TemplateBinding Padding}"
                             Orientation="Horizontal"
                             SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
                             SeparatorBrush="{TemplateBinding SeparatorBrush}" Margin="0,-1,0,0">

                    <StackPanel Orientation="Horizontal">
                        <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                          VerticalAlignment="Center"/>
                        <Control SnapsToDevicePixels="false"
                   Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type Custom:DataGridRow}},
                            Path=(Validation.HasError),
                   Converter={StaticResource bool2VisibilityConverter}}"
                   Template="{Binding RelativeSource={RelativeSource AncestorType={x:Type Custom:DataGridRow}},
                            Path=ValidationErrorTemplate}" />
                    </StackPanel>
                </Custom:DataGridHeaderBorder>
                <Thumb x:Name="PART_TopHeaderGripper"
           VerticalAlignment="Top" Height="3"
           Style="{StaticResource RowHeaderGripperStyle}"/>
                <Thumb x:Name="PART_BottomHeaderGripper"
           VerticalAlignment="Bottom" Height="3"
           Style="{StaticResource RowHeaderGripperStyle}"/>
            </Grid>

            <ControlTemplate.Triggers>                       
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="{StaticResource RowHeaderIsMouseOverBrush}" />
                </Trigger>
                <Trigger Property="IsRowSelected" Value="True">
                    <Setter Property="Background" Value="{StaticResource RowBackgroundSelectedBrush}" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Setter.Value>
</Setter>

How do I use the following style for gridview

<Stylex:Key="{x:TypeCustom:DataGridRowHeader}"TargetType="{x:TypeCustom:DataGridRowHeader}">
<SetterProperty="Background"Value="{StaticResource RowHeaderBackgroundBrush}" />     
<SetterProperty="Template">
    <Setter.Value>
        <ControlTemplate TargetType="{x:TypeCustom:DataGridRowHeader}">
            <Grid>                       
                <Custom:DataGridHeaderBorder IsSelected="{TemplateBinding IsRowSelected}"
                             IsHovered ="{TemplateBinding IsMouseOver}"
                             IsPressed="{TemplateBinding IsPressed}"
                             BorderBrush="{Binding RelativeSource={RelativeSource AncestorType={x:Type Custom:DataGrid}},
                                Path=HorizontalGridLinesBrush}"
                             Background="{TemplateBinding Background}"                                    
                             BorderThickness="0,1,0,0"
                             Padding ="{TemplateBinding Padding}"
                             Orientation="Horizontal"
                             SeparatorVisibility="{TemplateBinding SeparatorVisibility}"
                             SeparatorBrush="{TemplateBinding SeparatorBrush}" Margin="0,-1,0,0">

                    <StackPanel Orientation="Horizontal">
                        <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                          VerticalAlignment="Center"/>
                        <Control SnapsToDevicePixels="false"
                   Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type Custom:DataGridRow}},
                            Path=(Validation.HasError),
                   Converter={StaticResource bool2VisibilityConverter}}"
                   Template="{Binding RelativeSource={RelativeSource AncestorType={x:Type Custom:DataGridRow}},
                            Path=ValidationErrorTemplate}" />
                    </StackPanel>
                </Custom:DataGridHeaderBorder>
                <Thumb x:Name="PART_TopHeaderGripper"
           VerticalAlignment="Top" Height="3"
           Style="{StaticResource RowHeaderGripperStyle}"/>
                <Thumb x:Name="PART_BottomHeaderGripper"
           VerticalAlignment="Bottom" Height="3"
           Style="{StaticResource RowHeaderGripperStyle}"/>
            </Grid>

            <ControlTemplate.Triggers>                       
                <Trigger Property="IsMouseOver" Value="True">
                    <Setter Property="Background" Value="{StaticResource RowHeaderIsMouseOverBrush}" />
                </Trigger>
                <Trigger Property="IsRowSelected" Value="True">
                    <Setter Property="Background" Value="{StaticResource RowBackgroundSelectedBrush}" />
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    </Setter.Value>
</Setter>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

哆啦不做梦 2024-12-03 18:06:45

如果我没有记错的话,您需要的是网格视图中类似样式的标题。我假设您需要的是网格视图列标题样式。为此,您可以使用现有的 xaml 并将类名(例如 x:TypeCustom:DataGridRowHeader 更改为 x:Type GridViewColumnHeader)。

将 Custom:DataGridHeaderBorder 更改为普通边框。就是这样。希望您已经获得了您提到的所有其他静态资源,例如 RowHeaderGripperStyle。快乐编码:)

If i am not mistaken, what you need is a similiar style header in a grid view. I assume what u need is a grid view column header style. For that you can use the existing xaml as such and chnage the classnames like x:TypeCustom:DataGridRowHeader to x:Type GridViewColumnHeader.

Change the Custom:DataGridHeaderBorder to a normal Border. And thats it. Hope you have got all other static resources that you mentioned like RowHeaderGripperStyle with you. Happy coding :)

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