1
Answer

Columns headers

person

person

15y
2.5k
1
Hi,

I was wondering if

A) - there was a way to restrict the resizing of columns when using GridViewRowHeaderPresenter, and/or
B) - Mimicking the look and feel of general columns headers?


Thanks in advance.

Urema.
Answers (1)
0
Roei Bar

Roei Bar

NA 7.8k 0 15y
well about first question you can restrict the size of header columns here is a sample code:

Try with a template without the PART_HeaderGripper.





    <Style x:Key="{x:Type GridViewColumnHeader}" TargetType="{x:Type GridViewColumnHeader}">
        <Setter Property="HorizontalContentAlignment" Value="Center"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        <Setter Property="Background" Value="{StaticResource GridViewColumnHeaderBackground}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="Padding" Value="2,0,2,0"/>
        <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                    <Grid SnapsToDevicePixels="true"
                          Background="{TemplateBinding Background}">
                        <Border x:Name="HighlightBorder"
                                VerticalAlignment="Bottom"
                                Background="{StaticResource GridViewColumnHeaderHighlightBackground}"
                                BorderBrush="{StaticResource GridViewColumnHeaderDarkBackground}"
                                Height="3"
                                BorderThickness="0,0,0,1"/>
                        <Border BorderThickness="{TemplateBinding BorderThickness}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                Padding="{TemplateBinding Padding}"
                                Margin="1,0,1,0">
                            <ContentPresenter x:Name="HeaderContent"
                                              Margin="0,0,0,1"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              RecognizesAccessKey="True"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Border>
                        <Canvas>
                        <!--
                            <Thumb x:Name="PART_HeaderGripper" Style="{StaticResource GridViewColumnHeaderGripper}"/>
                        -->
                        </Canvas>
                        <Border x:Name="HeaderPressBorder" BorderThickness="1"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="HighlightBorder" Property="BorderBrush"
                                    Value="{StaticResource TabItemHotBorderBrush}"/>
                            <Setter TargetName="HighlightBorder" Property="Background"
                                    Value="{StaticResource TabItemHotBorderBackround}"/>
                            <Setter TargetName="HighlightBorder" Property="CornerRadius" Value="0,0,3,3"/>
                            <Setter TargetName="HighlightBorder" Property="BorderThickness" Value="1,0,1,1"/>
                           
<!-- <Setter TargetName="PART_HeaderGripper"
Property="Background" Value="Transparent"/> -->
                            <Setter Property="Background" Value="{StaticResource GridViewColumnHeaderHoverBackground}"/>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter TargetName="HighlightBorder" Property="Visibility" Value="Hidden"/>
                            <Setter TargetName="PART_HeaderGripper" Property="Visibility" Value="Hidden"/>
                           
<Setter TargetName="HeaderPressBorder" Property="BorderBrush"
Value="{StaticResource GridViewColumnHeaderPressBorder}"/>
                            <Setter TargetName="HeaderPressBorder" Property="Margin" Value="1,0,0,0"/>
                            <Setter TargetName="HeaderContent" Property="Margin" Value="1,1,0,0"/>
                            <Setter Property="Background" Value="{StaticResource GridViewColumnHeaderPressBackground}"/>
                            <Setter Property="BorderBrush" Value="{StaticResource GridViewColumnHeaderPressBackground}"/>
                        </Trigger>
                        <Trigger Property="Height" Value="Auto">
                            <Setter Property="MinHeight" Value="20"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                           
<Setter Property="Foreground" Value="{DynamicResource {x:Static
SystemColors.GrayTextBrushKey}}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="Role" Value="Floating">
                <Setter Property="Opacity" Value="0.7"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                            <Canvas Name="PART_FloatingHeaderCanvas" />
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="Role" Value="Padding">
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type GridViewColumnHeader}">
                            <Grid Background="{TemplateBinding Background}" SnapsToDevicePixels="true">
                                <Border VerticalAlignment="Bottom"
                                        Background="{StaticResource GridViewColumnHeaderHighlightBackground}"
                                        BorderBrush="{StaticResource GridViewColumnHeaderDarkBackground}"
                                        Height="3"
                                        BorderThickness="0,0,0,1"/>
                                <Border BorderThickness="{TemplateBinding BorderThickness}"
                                        BorderBrush="{TemplateBinding BorderBrush}"
                                        Padding="{TemplateBinding Padding}"
                                        Margin="1,0,1,0"/>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="Height" Value="Auto">
                                    <Setter Property="MinHeight" Value="20"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Trigger>
        </Style.Triggers>
    </Style>

i didnt quite understand the second part