none
Getting the mouse cursor to change to a Hand (or anything) when mouse is over GridSplitter

    Question

  • Thais has to be something simple that I just can't figure out. I have a GridSplitter. I want the mouse cursor to change from the normal Arrow to a Hand when it enters the GridSplitter and then change back to an Arrow when it leaves. I tried StoryBoards and simply changing the Cursor property of the GridSplitter without success. Any suggestions?

     

    M


    Michael
    Thursday, April 21, 2011 12:25 AM

Answers

  • Hi micheal hockstein,

    I think Reylnet's link is a good solution for your issue.

    Refer to below code snippet:

    <GridSplitter Grid.Column="1" ResizeDirection="Columns" Background="LightGray" Width="10" MouseEnter="GridSplitter_MouseEnter" MouseLeave="GridSplitter_MouseLeave"/>

     

    private void GridSplitter_MouseEnter(object sender, MouseEventArgs e)

    {

        if (this.Cursor != Cursors.Wait)

            Mouse.OverrideCursor = Cursors.Hand;

    }

     

    private void GridSplitter_MouseLeave(object sender, MouseEventArgs e)

    {

        if (this.Cursor != Cursors.Wait)

            Mouse.OverrideCursor = Cursors.Arrow;

    }

    If your issue persists, could you share your develop environment and a sample with me to reproduece your issue.

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 21, 2011 4:58 AM
    Moderator

All replies

  • This is working for me:

     <Grid>
      <Grid.ColumnDefinitions>
       <ColumnDefinition />
       <ColumnDefinition Width="10" />
       <ColumnDefinition />
      </Grid.ColumnDefinitions>
      <GridSplitter Grid.Column="1" Cursor="Hand" Background="#FFE22B2B" Width="10" />
     </Grid>
    
    I'm thinking maybe you don't have enough width or no background on your splitter.


    John Fenton, MCC
    Wordmasters Direct Mail and Data Processing Services
    Thursday, April 21, 2011 1:25 AM
  • I followed your code exactly. Still can't get the mouse cursor to change to the Hand when over the GridSplitter then back to an Arrow when off it.

     

    M


    Michael
    Thursday, April 21, 2011 2:44 AM
  • Maybe the following might help:

    http://social.msdn.microsoft.com/Forums/pl-PL/wpfprerelease/thread/c3c192af-4666-47ac-836c-803148a35207


    WPF and .NET Tutorials Aggregator
    Thursday, April 21, 2011 3:18 AM
  • It would be interesting if you post some code.

    Because, if any control overlays your grid splitter then it would be possible, too.

    Thursday, April 21, 2011 4:48 AM
  • Hi micheal hockstein,

    I think Reylnet's link is a good solution for your issue.

    Refer to below code snippet:

    <GridSplitter Grid.Column="1" ResizeDirection="Columns" Background="LightGray" Width="10" MouseEnter="GridSplitter_MouseEnter" MouseLeave="GridSplitter_MouseLeave"/>

     

    private void GridSplitter_MouseEnter(object sender, MouseEventArgs e)

    {

        if (this.Cursor != Cursors.Wait)

            Mouse.OverrideCursor = Cursors.Hand;

    }

     

    private void GridSplitter_MouseLeave(object sender, MouseEventArgs e)

    {

        if (this.Cursor != Cursors.Wait)

            Mouse.OverrideCursor = Cursors.Arrow;

    }

    If your issue persists, could you share your develop environment and a sample with me to reproduece your issue.

     

    Best regards,


    Sheldon _Xiao[MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, April 21, 2011 4:58 AM
    Moderator
  • OK, I'll give this a try.
    Michael
    Thursday, April 21, 2011 5:58 AM
  • Worked great. thanks

     

    M


    Michael
    Thursday, April 21, 2011 11:20 AM
  • Sheldon,

    There is a problem with that code, specifically this:

    private void GridSplitter_MouseLeave(object sender, MouseEventArgs e)

    {

        if (this.Cursor != Cursors.Wait)

            Mouse.OverrideCursor = Cursors.Arrow;

    }

     

    That's going to leave the Mouse with an overridden cursor of Cursors.Arrow.

     

    Any cursor settings like this.Cursor, will now be broken.  Because they are now all overridden.

     

    At minimum, it should be:

     

    Mouse.OverrideCursor = null;

     

    That code will clear the the override.

     

    A mouse cursor that was left in an overridden state would actually explain why my code didn't work.

     

    Edit: I only use Mouse.OverrideCursor for wait cursors, it works better than this.Cursor for that because it overrides the cursor setting on all FrameworkElements. That way your wait cursor stays as a wait cursor no matter where it is hovered.

     

    If you are going to use it for more than that, you should probably store it's value before you set it, and restore that value when you are done.



    John Fenton, MCC
    Wordmasters Direct Mail and Data Processing Services


    Thursday, April 21, 2011 5:11 PM
  • Michael,

    I'm curious if this also works:

    <GridSplitter Grid.Column="1" ResizeDirection="Columns" Background="LightGray" Width="10" Cursor="Hand" MouseEnter="GridSplitter_MouseEnter" />

     

    private void GridSplitter_MouseEnter(object sender, MouseEventArgs e)

    {

          Mouse.OverrideCursor = null;

    }

     

    If it does, it means that something somewhere else in your code is leaving the mouse in an overridden state. 

    John Fenton, MCC
    Wordmasters Direct Mail and Data Processing Services
    Thursday, April 21, 2011 6:16 PM