如何在使用 ZoomToFactor 增加按钮单击时的缩放级别时在滚动查看器中缩放
How to zoom at center in scroll viewer while using ZoomToFactor to increase zoom level in button click
我正在使用滚动查看器来缩放设置为 Grid.When 背景的图像,我在使用 scrollViewer.ZoomToFactor(zoomFactor) 图像设置按钮点击时的缩放系数值是从左上角开始放大,而不是从中心位置开始。
请从下面link或下面的代码片段中获取示例以供参考。
Link: https://github.com/ragulsv/ScrollViewer
代码片段[C#]:
float count = 1;
private void Clr_Click(object sender, RoutedEventArgs e)
{
count = 1;
viewer.ZoomToFactor(count);
viewer.RenderTransformOrigin = new Point(0.5, 0.5);
}
private void Btn_Click(object sender, RoutedEventArgs e)
{
viewer.ZoomToFactor(count);
viewer.RenderTransformOrigin = new Point(0.5, 0.5);
count += 1;
}
代码片段[Xaml]:
<Grid x:Name="grid1">
<Grid.RowDefinitions>
<RowDefinition Height="0.1*">
</RowDefinition>
<RowDefinition Height="0.1*">
</RowDefinition>
<RowDefinition Height="0.8*">
</RowDefinition>
</Grid.RowDefinitions>
<Button x:Name="btn" Grid.Row="0"></Button>
<Button x:Name="clr" Grid.Row="1"></Button>
<ScrollViewer x:Name="viewer" Grid.Row="2" ZoomMode="Enabled">
<Grid>
<Image Source="Assets\EditedImage.jpg" Height="190" Width="190"/>
</Grid>
</ScrollViewer>
</Grid>
How to zoom at center in scroll viewer while using ZoomToFactor to increase zoom level in button click
对于这种情况,可以设置图片的parentGrid
VerticalAlignment="Center" HorizontalAlignment="Center"
,使图片始终固定在ScrollViewer
的中心,然后调用ChangeView方法进行编辑ZoomFactor
.
private void Btn_Click(object sender, RoutedEventArgs e)
{
viewer.ChangeView(0, 0, (viewer.ZoomFactor + 1f));
}
我正在使用滚动查看器来缩放设置为 Grid.When 背景的图像,我在使用 scrollViewer.ZoomToFactor(zoomFactor) 图像设置按钮点击时的缩放系数值是从左上角开始放大,而不是从中心位置开始。
请从下面link或下面的代码片段中获取示例以供参考。 Link: https://github.com/ragulsv/ScrollViewer
代码片段[C#]:
float count = 1;
private void Clr_Click(object sender, RoutedEventArgs e)
{
count = 1;
viewer.ZoomToFactor(count);
viewer.RenderTransformOrigin = new Point(0.5, 0.5);
}
private void Btn_Click(object sender, RoutedEventArgs e)
{
viewer.ZoomToFactor(count);
viewer.RenderTransformOrigin = new Point(0.5, 0.5);
count += 1;
}
代码片段[Xaml]:
<Grid x:Name="grid1">
<Grid.RowDefinitions>
<RowDefinition Height="0.1*">
</RowDefinition>
<RowDefinition Height="0.1*">
</RowDefinition>
<RowDefinition Height="0.8*">
</RowDefinition>
</Grid.RowDefinitions>
<Button x:Name="btn" Grid.Row="0"></Button>
<Button x:Name="clr" Grid.Row="1"></Button>
<ScrollViewer x:Name="viewer" Grid.Row="2" ZoomMode="Enabled">
<Grid>
<Image Source="Assets\EditedImage.jpg" Height="190" Width="190"/>
</Grid>
</ScrollViewer>
</Grid>
How to zoom at center in scroll viewer while using ZoomToFactor to increase zoom level in button click
对于这种情况,可以设置图片的parentGrid
VerticalAlignment="Center" HorizontalAlignment="Center"
,使图片始终固定在ScrollViewer
的中心,然后调用ChangeView方法进行编辑ZoomFactor
.
private void Btn_Click(object sender, RoutedEventArgs e)
{
viewer.ChangeView(0, 0, (viewer.ZoomFactor + 1f));
}