Mouse events triggering

312
1
04-05-2022 01:24 PM
VanyaIvanov
Occasional Contributor

I want to show current scene scale while scrolling the scene by mouse.

My mouse event handlers in MainWindow.xaml.cs:

private void MySceneView_MouseScroll(object sender, MouseWheelEventArgs e)
{
    Viewpoint current = MySceneView.GetCurrentViewpoint(ViewpointType.CenterAndScale);
    ((SceneViewModel)DataContext).Scale = System.Math.Round(current.TargetScale, 2);//I try to write the current scale on the interface TextBlock
}
But it seems that event doesnt work while scrolling scene by mouse(map scaling) so i dont get the current Scene scale value.

I also tried another event MouseWheel and it doesn't triggers also when i try to scroll the scene:

private void MySceneView_MouseWheel(object sender, MouseWheelEventArgs e)
{
  Viewpoint current = MySceneView.GetCurrentViewpoint(ViewpointType.CenterAndScale);
  ((SceneViewModel)DataContext).Scale = System.Math.Round(current.TargetScale, 2);

}

 My SceneView definition in the MainWindow.xaml:

<esri:SceneView Grid.Column ="0" x:Name ="MySceneView" Scene="{Binding Scene}" MouseWheel="MySceneView_MouseWheel" MouseMove="MySceneView_MouseMove" Margin="0,0,0,-0.4" HorizontalAlignment="Left" Width="774"/>

How can i solve it?

0 Kudos
1 Reply
JenniferNeryEsri
New Contributor II

I think you can use GeoView.ViewpointChanged event for this purpose. You can try the following code.

MySceneView.ViewpointChanged += (a, b) =>
  {
      System.Diagnostics.Debug.WriteLine(MySceneView.GetCurrentViewpoint(ViewpointType.CenterAndScale)?.TargetScale);
  };
MySceneView.Scene = new Scene(new Basemap(new OpenStreetMapLayer()));
0 Kudos