Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
340
xamgrid sorting fails on applying header style
posted

Style :

<Style x:Key="HeaderCellControlStyle"
           TargetType="igPrim:HeaderCellControl">
        <!--<Setter Property="Margin"
                Value="-8,0,0,0"></Setter>-->
        <Setter Property="HorizontalContentAlignment"
                Value="Stretch"></Setter>
        <Setter Property="BorderThickness"
                Value="0" />
        <Setter Property="Foreground"
                Value="Black" />
        <Setter Property="VerticalContentAlignment"
                Value="Center" />
        <Setter Property="FontWeight"
                Value="Bold"></Setter>
        <Setter Property="Padding"
                Value="0, 0, 5, 0" />
        <Setter Property="FontFamily"
                Value="Segoe UI" />
        <Setter Property="FontSize"
                Value="9" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid>
                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualState x:Name="Normal">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames            Storyboard.TargetName="GridCellNormalFill"
                                                                                  Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames            Storyboard.TargetName="GridCellNormalBorder"
                                                                                  Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames            Storyboard.TargetName="GridCellMouseOverFill"
                                                                                  Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames            Storyboard.TargetName="GridCellMouseOverBorder"
                                                                                  Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                                <vsm:VisualState x:Name="Alternate">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridCellAlternateFill"
                                                                       Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="GridCellAlternateBorder"
                                                                       Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>
                            </vsm:VisualStateGroup>
                            <vsm:VisualStateGroup x:Name="SelectedStates">
                                <VisualState x:Name="NotSelected" />
                                <VisualState x:Name="Selected">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames           Storyboard.TargetName="GridCellSelectedFill"
                                                                                 Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames            Storyboard.TargetName="GridCellSelectedBorder"
                                                                                  Storyboard.TargetProperty="(UIElement.Visibility)">
                                            <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                <DiscreteObjectKeyFrame.Value>
                                                    <Visibility>Visible</Visibility>
                                                </DiscreteObjectKeyFrame.Value>
                                            </DiscreteObjectKeyFrame>
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>
                        <Border x:Name="GridCellNormalFill"
                                BorderBrush="White"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Visibility="Collapsed">
                            <Border.Background>
                                <SolidColorBrush Color="White"></SolidColorBrush>
                            </Border.Background>
                        </Border>

                        <Rectangle x:Name="GridCellNormalBorder"
                                   Fill="Black"
                                   Opacity=".6"
                                   Visibility="Collapsed"
                                   Margin="0,0,1,0"
                                   Height="1"
                                   VerticalAlignment="Bottom" />
                        <Border x:Name="GridCellMouseOverFill"
                                BorderBrush="#FFFFFFCE"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Visibility="Collapsed">
                            <Border.Background>
                                <SolidColorBrush Color="#FFFFFFCE" />
                            </Border.Background>
                        </Border>

                        <Rectangle x:Name="GridCellMouseOverBorder"
                                   Fill="Black"
                                   Visibility="Collapsed"
                                   Margin="-10,0,1,0"
                                   Height="1"
                                   VerticalAlignment="Bottom" />
                        <Rectangle x:Name="GridCellSelectedBorder"
                                   Fill="#FFFFFFCE"
                                   Visibility="Collapsed"
                                   Margin="1,0,1,0"
                                   Height="1"
                                   VerticalAlignment="Bottom" />
                        <Border x:Name="GridCellSelectedFill"
                                BorderBrush="#FFB1C5DE"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Visibility="Collapsed">
                            <Border.Background>
                                <SolidColorBrush Color="#FFB1C5DE" />
                            </Border.Background>
                        </Border>

                        <ContentPresenter        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                                 HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                 Margin="{TemplateBinding Padding}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

........................................................................................................

<ig:XamGrid Name="xgridList"
                    AutoGenerateColumns="False"
                    Grid.Row="1"
                    Grid.Column="0"
                    ColumnWidth="*"
                    HorizontalAlignment="Left"
                    ScrollViewer.HorizontalScrollBarVisibility="Auto"
                    ScrollViewer.VerticalScrollBarVisibility="Auto"
                    ItemsSource="{Binding Path=List}"
                    CellDoubleClicked="XgridList_CellDoubleClicked"
                    SelectedRowsCollectionChanged="XgridList_SelectedRowsCollectionChanged"
                    HeaderStyle="{StaticResource HeaderCellControlStyle}">
            <ig:XamGrid.RowSelectorSettings>
                <ig:RowSelectorSettings Visibility="Collapsed"
                                        EnableRowNumbering="False" />
            </ig:XamGrid.RowSelectorSettings>

.

.

.

</ig:XamGrid>

  • 6912
    Verified Answer
    posted

    Hi,

    I guess you are asking why you can't sort the columns when you click on the header?

    It seems that you use a control template from a regular XamGrid's CellControl and just changed the TargetType. The ControlTemplate above has few missing parts, commands and visual states that are specific for the HeaderCellControl.

    I would suggest you to take a look at the default control template of the XamGrid and reuse/modify the control template of the HeaderCellControl. Note that the sorting commands are attached to a SimpleClickable container:

    ...
    <ControlTemplate TargetType="igPrim:HeaderCellControl">
       <igPrim:SimpleClickableContainer ... >
           <igBase:Commanding.Commands>
               <igBase:CommandSourceCollection>
                   <ig:XamGridColumnCommandSource CommandType="Select" EventName="SimpleClick"/>
                   <ig:XamGridColumnCommandSource CommandType="SortToggle" EventName="SimpleClick"/>
               </igBase:CommandSourceCollection>
            </igBase:Commanding.Commands>
    ...
    

    HTH