We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

Panning with Middle Mouse Button

How can I do that ?

1 Reply

MK Muneesh Kumar G Syncfusion Team March 12, 2019 10:25 AM UTC

Hi xmen, 
 
Greetings from Syncfusion, we have analyzed your requirement and you can achieve this by extending SfChart and ChartZoomPanBehavior then overriding MouseDown and MouseUp event as per the below code snippet.  
 
Code snippet 
public class SfChartExt : SfChart 
    { 
        protected override void OnMouseDown(MouseButtonEventArgs e) 
        { 
            base.OnMouseDown(e); 
 
            if (e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Pressed) 
                foreach (var behavior in Behaviors) 
                { 
                    if (behavior is ChartZoomPanBehaviorExt) 
                        (behavior as ChartZoomPanBehaviorExt).MouseLeftButtonDown(e); 
                } 
        } 
 
        protected override void OnMouseUp(MouseButtonEventArgs e) 
        { 
            base.OnMouseUp(e); 
 
            if (e.ChangedButton == MouseButton.Middle && e.ButtonState == MouseButtonState.Released) 
                foreach (var behavior in Behaviors) 
                { 
                    if (behavior is ChartZoomPanBehaviorExt) 
                        (behavior as ChartZoomPanBehaviorExt).MouseLeftButtonUp(e); 
 
                } 
        } 
    } 
 
    public class ChartZoomPanBehaviorExt : ChartZoomPanBehavior 
    { 
        public void MouseLeftButtonUp(MouseButtonEventArgs e) 
        { 
            OnMouseLeftButtonUp(e); 
        } 
 
        public void MouseLeftButtonDown(MouseButtonEventArgs e) 
        { 
            OnMouseLeftButtonDown(e); 
        } 
    } 
 
 
  <local:SfChartExt Margin="10" x:Name="chart" PanChanging="chart_PanChanging"> 
 
            <chart:SfChart.Behaviors> 
 
                <local:ChartZoomPanBehaviorExt EnablePanning="True" EnableMouseWheelZooming="True" /> 
 
            </chart:SfChart.Behaviors> 
            .. 
 
        </local:SfChartExt> 
 
Here we have checked the mouse state and changed button for middle button identification.  
 
 
Hope it helps you.  
 
Thanks, 
Muneesh Kumar G.  
 


Loader.
Live Chat Icon For mobile
Up arrow icon