How to get Zoom value in scroll viewer in C# wpf Kinect SDK 2.0?
This has nothing to do with Kinect SDK, this is more of a ScrollViewer
zooming issue. There is no k:KinectRegion.ZoomFactor
because zooming doesn't change the actual size of the image, it only performs some layout transformations, therefore you can get the zooming factor from LayoutTransform
property of your Image
.
Something like the following code should get the zooming factor:
UserControl.Code:
public NavigationImage() { InitializeComponent(); DataContext = this; _zoom = 1.0; } double _zoom; public string ZoomPercentage { get { return _zoom * 100 + "%"; } } private void scrollViewer_MouseWheel(object sender, MouseWheelEventArgs e) { if (e.Delta > 0) { _zoom += 0.1; } else { _zoom -= 0.1; } ScaleTransform scale = new ScaleTransform(_zoom, _zoom); navigationImage.LayoutTransform = scale; OnPropertyChanged("ZoomPercentage"); e.Handled = true; }
UserControl.Xaml:
<UserControl x:Class="ImageNav.NavigationImage" ... > <Grid Grid.RowSpan="2"> <ScrollViewer Name="scrollViewer" Grid.Row="0" PreviewMouseWheel="scrollViewer_MouseWheel" .... HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" k:KinectRegion.IsHorizontalRailEnabled="true" k:KinectRegion.IsVerticalRailEnabled="true" k:KinectRegion.ZoomMode="Enabled" > <Image Name="navigationImage" RenderTransformOrigin="0.5, 0.5"/> </ScrollViewer> <TextBox x:Name="ZoomTextBox" Grid.Row="1" Text="{Binding ZoomPercentage, Mode=OneWay}" .... /> </Grid></UserControl>