How to get the scrolling state in Xamarin MacOS?

KyuubiKyuubi USMember ✭✭

Hi All,

I would like to get the scrolling states of the ScrollView while performing the below actions in Mac.

  • Performing fling action.
  • Panning across the window by double finger swipe.
  • Performing programmatic scrolling by using ScrollTo method.
  • Idle state.

Is there any easiest way to achieve the scrolling states. It would be highly helpful if you could direct me to the documentation regarding this.

Thanks.

Best Answers

  • KyuubiKyuubi US ✭✭
    edited August 2018 Accepted Answer

    While the scrollview is in dragging state, its MomentumPhase will be none and thus the EventPhase will not began and end to determine the idle state. So while drag stopped, it is still in 'Drag' state instead of 'Idle' state.
    So instead of using MomentumPhase, Just use Phase to detect the began and end events as like below.

    public override void ScrollWheel(NSEvent theEvent)
            {
                base.ScrollWheel(theEvent);
                if (theEvent.Phase == NSEventPhase.Changed)
                {
                    //Dragging state
                }
                else if (theEvent.MomentumPhase == NSEventPhase.Changed)
                {
                    //Fling state
                }
                else if (theEvent.Phase == NSEventPhase.Ended || theEvent.MomentumPhase == NSEventPhase.Ended)
                {
                    //Idle state
                }
            }
    

Answers

  • ChrisHamonsChrisHamons USForum Administrator, Xamarin Team Xamurai

    Just a bit of forum formatting here, I updated your answer to use a code block which is much more readable.

    If you hilight your code block and click the formatting button (6th from the left) then code, it will indent it in a block that has c# formatting by default.

  • KyuubiKyuubi USMember ✭✭
    edited August 2018 Accepted Answer

    While the scrollview is in dragging state, its MomentumPhase will be none and thus the EventPhase will not began and end to determine the idle state. So while drag stopped, it is still in 'Drag' state instead of 'Idle' state.
    So instead of using MomentumPhase, Just use Phase to detect the began and end events as like below.

    public override void ScrollWheel(NSEvent theEvent)
            {
                base.ScrollWheel(theEvent);
                if (theEvent.Phase == NSEventPhase.Changed)
                {
                    //Dragging state
                }
                else if (theEvent.MomentumPhase == NSEventPhase.Changed)
                {
                    //Fling state
                }
                else if (theEvent.Phase == NSEventPhase.Ended || theEvent.MomentumPhase == NSEventPhase.Ended)
                {
                    //Idle state
                }
            }
    
Sign In or Register to comment.