C1DataGrid DataGridVerticalFreezingSeparatorPresenter Cursor

Posted by: frugamas on 17 February 2021, 1:06 am EST

  • Posted 17 February 2021, 1:06 am EST

    I'm trying to change the cursor for the Vertical Freezing Separator from the SizeWE to my own cursor.

    I have defined the style for the presenter and have been trying to test it with the Hand cursor.

    Here is the style a created in Blend and add the Cursor Setter.


    <Style x:Key="c1VerticalFreezingSeparatorStyle" TargetType="{x:Type c1:DataGridVerticalFreezingSeparatorPresenter}">
    <Setter Property="Cursor" Value="Hand"/>
    <Setter Property="Template">
    <Setter.Value>
    <ControlTemplate TargetType="{x:Type c1:DataGridVerticalFreezingSeparatorPresenter}">
    <Grid>
    <VisualStateManager.VisualStateGroups>
    <VisualStateGroup x:Name="MovementStates">
    <VisualState x:Name="Normal"/>
    <VisualState x:Name="MouseOver">
    <Storyboard>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="RectMouseOver">
    <DiscreteObjectKeyFrame KeyTime="0">
    <DiscreteObjectKeyFrame.Value>
    <Visibility>Visible</Visibility>
    </DiscreteObjectKeyFrame.Value>
    </DiscreteObjectKeyFrame>
    </ObjectAnimationUsingKeyFrames>
    </Storyboard>
    </VisualState>
    <VisualState x:Name="Dragging">
    <Storyboard>
    <ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Visibility)" Storyboard.TargetName="RectDragging">
    <DiscreteObjectKeyFrame KeyTime="0">
    <DiscreteObjectKeyFrame.Value>
    <Visibility>Visible</Visibility>
    </DiscreteObjectKeyFrame.Value>
    </DiscreteObjectKeyFrame>
    </ObjectAnimationUsingKeyFrames>
    </Storyboard>
    </VisualState>
    </VisualStateGroup>
    </VisualStateManager.VisualStateGroups>
    <c1:C1BrushBuilder x:Name="BackgroundBrush" DesignBrush="#FFD1DCE8" DesignColor="#FFD1DCE8" ExtrapolationMethod="Absolute" Input="{TemplateBinding Background}"/>
    <c1:C1BrushBuilder x:Name="MouseOverBrush" DesignBrush="#FFBFE1EA" DesignColor="#FFBFE1EA" ExtrapolationMethod="Absolute" Input="{TemplateBinding MouseOverBrush}"/>
    <Border x:Name="Rect" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="0,0,1,0" Background="{Binding Output, ElementName=BackgroundBrush}"
    Cursor="Hand"/>
    <Border x:Name="RectDragging" BorderThickness="0,0,1,0" Background="{TemplateBinding PressedBrush}" Visibility="Collapsed"/>
    <Border x:Name="RectMouseOver" BorderThickness="0,0,1,0" Background="{Binding Output, ElementName=MouseOverBrush}" Visibility="Collapsed"/>
    </Grid>
    </ControlTemplate>
    </Setter.Value>
    </Setter>
    </Style>


    I then applied the style to the VerticalFreezingSeparatorStyle on the data grid.

    This does not seem work. I changed some colors and used Snoop to verify that the new style has been applied.

    It looks like the cursor is being overridden in code somewhere.

    What is the best way to override the cursor?

    Thanks,

    FR
  • Replied 17 February 2021, 10:26 pm EST

    Hi Felix,

    Thank you for sharing the code snippet.

    You need to change the Cursor property of the Rectangle (named Resize) present inside the ColumnHeaderStyle. However, it will change the cursor for all the columns. So, you can use a converter to the change the cursor only for the frozen column.

    Please refer to the attached sample for the same. (see DataGridFreezingCursor.zip)

    Best Regards,
    Kartik

    DataGridFreezingCursor.zip
  • Replied 18 February 2021, 3:24 am EST

    Thanks Kartik,

    I looked at the example you sent, but it does not quite do what I want. The code simply changes the resize cursor of the column headers. I'm looking to change the cursor over the Freeze Bar, see https://www.grapecity.com/componentone/docs/wpf/online-datagrid/FreezingColumns.html.

    Adding the CanUserFreezeColumns="Left" property on the datagrid illustrates the issue and shows the SizeWE cursor over the entire Freeze Bar.

    Thanks,

    Felix


  • Marked as Answer

    Replied 18 February 2021, 4:35 pm EST

    Hi Felix,

    Thank you for sharing the information.

    You can set the root Grid's (present inside vertical seperator style) Cursor property for changing the cursor on mouse over.

    However, the cursor displayed (when mouse is clicked on the seperator) is internally handled by the DataGrid. Therefore, you can override this behavior by handling the Border's (named RectMouseOver) PreviewMouseLeftButtonDown event and DataGrid's PreviewMouseLeftButtonUp event as follows:

    private void Rect_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
    {
    Mouse.OverrideCursor = Cursors.Hand;
    }

    private void DataGrid_PreviewMouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {
    Mouse.OverrideCursor = null;
    }

    Please refer to the same from the attached modified sample. (see DataGridFreezingCursor_Mod.zip)

    Best Regards,
    Kartik
  • Replied 18 February 2021, 4:36 pm EST

    DataGridFreezingCursor_Mod.zip
  • Replied 22 February 2021, 2:42 am EST

    Thanks Kartik, this works.
Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels