开发者

Using style for gridview

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>


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜