UWP ListView ScrollViewer - 重置缩放(因子)
UWP ListView ScrollViewer - Reset Zoom (Factor)
我的 ListView 包含 BitmapImages,我想允许放大这些图像。
如果我去 ScrollViewer。 ...我没有得到缩放因子。
<UserControl
x:Class="SimplePdfViewer.SimplePdfViewerControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SimplePdfViewer"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Unloaded="root_Unloaded"
x:Name="root">
<UserControl.Resources>
<Style TargetType="ListViewItem" x:Key="ListViewItemEdit">
<!-- spacing between pages-->
<Setter Property="Margin" Value="0 0 0 3"/>
<!-- Setting Background Color of PDf Placeholders to White-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter ContentTransitions="{TemplateBinding ContentTransitions}"
PlaceholderBackground="White"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<ListView x:Name="PdfListView"
ItemsSource="{x:Bind DocumentDataSource}"
ScrollViewer.ZoomMode="Enabled"
ItemContainerStyle="{StaticResource ListViewItemEdit}"
SelectionMode="None">
<ListView.ItemTemplate>
<!-- Implement Dynamic Width! -> Added for Placeholder Width -->
<DataTemplate x:DataType="BitmapImage">
<ListViewItem
Height="1180"
Width="800"
Background="White"
IsHitTestVisible="False">
<Image Source="{x:Bind}"/>
</ListViewItem>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
有没有办法将放大的图片重置为原始大小?
感谢大家的帮助加油!
如果您从滚动查看器中获得句柄,则可以使用 ScrollViewer.ChangeView()
设置图像的缩放程度。
是的,正如@user1419778 的回答,您应该找到 ScrollViewer object from the ListView, then you can use the ScrollViewer.ChangeView Method's zoomFactor
parameter to reset its ZoomFactor.
首先,您可以在助手 class.
中使用以下方法从 ListView 中找到 ScrollViewer 对象
public static class UIHelper
{
public static ChildElement FindVisualChild<ChildElement>(this DependencyObject obj)
where ChildElement : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is ChildElement)
return (ChildElement)child;
else
{
ChildElement childOfChild = FindVisualChild<ChildElement>(child);
if (childOfChild != null)
return childOfChild;
}
}
return null;
}
}
然后您可以获得 ScrollViewer 对象并在您的用户控件后面的代码中重置其 ZoomFactor。
private void ResetButton_Click(object sender, RoutedEventArgs e)
{
var scrollViewer=PdfListView.FindVisualChild<ScrollViewer>();
//change view to vertical offset and set the zoom factor to 1.
//The default zoom factor is 1.0, where 1.0 indicates no additional scaling
scrollViewer.ChangeView(0, scrollViewer.VerticalOffset, 1.0f);
}
我的 ListView 包含 BitmapImages,我想允许放大这些图像。
如果我去 ScrollViewer。 ...我没有得到缩放因子。
<UserControl
x:Class="SimplePdfViewer.SimplePdfViewerControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SimplePdfViewer"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Unloaded="root_Unloaded"
x:Name="root">
<UserControl.Resources>
<Style TargetType="ListViewItem" x:Key="ListViewItemEdit">
<!-- spacing between pages-->
<Setter Property="Margin" Value="0 0 0 3"/>
<!-- Setting Background Color of PDf Placeholders to White-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ListViewItem">
<ListViewItemPresenter ContentTransitions="{TemplateBinding ContentTransitions}"
PlaceholderBackground="White"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</UserControl.Resources>
<Grid>
<ListView x:Name="PdfListView"
ItemsSource="{x:Bind DocumentDataSource}"
ScrollViewer.ZoomMode="Enabled"
ItemContainerStyle="{StaticResource ListViewItemEdit}"
SelectionMode="None">
<ListView.ItemTemplate>
<!-- Implement Dynamic Width! -> Added for Placeholder Width -->
<DataTemplate x:DataType="BitmapImage">
<ListViewItem
Height="1180"
Width="800"
Background="White"
IsHitTestVisible="False">
<Image Source="{x:Bind}"/>
</ListViewItem>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
有没有办法将放大的图片重置为原始大小?
感谢大家的帮助加油!
如果您从滚动查看器中获得句柄,则可以使用 ScrollViewer.ChangeView()
设置图像的缩放程度。
是的,正如@user1419778 的回答,您应该找到 ScrollViewer object from the ListView, then you can use the ScrollViewer.ChangeView Method's zoomFactor
parameter to reset its ZoomFactor.
首先,您可以在助手 class.
中使用以下方法从 ListView 中找到 ScrollViewer 对象public static class UIHelper
{
public static ChildElement FindVisualChild<ChildElement>(this DependencyObject obj)
where ChildElement : DependencyObject
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(obj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(obj, i);
if (child != null && child is ChildElement)
return (ChildElement)child;
else
{
ChildElement childOfChild = FindVisualChild<ChildElement>(child);
if (childOfChild != null)
return childOfChild;
}
}
return null;
}
}
然后您可以获得 ScrollViewer 对象并在您的用户控件后面的代码中重置其 ZoomFactor。
private void ResetButton_Click(object sender, RoutedEventArgs e)
{
var scrollViewer=PdfListView.FindVisualChild<ScrollViewer>();
//change view to vertical offset and set the zoom factor to 1.
//The default zoom factor is 1.0, where 1.0 indicates no additional scaling
scrollViewer.ChangeView(0, scrollViewer.VerticalOffset, 1.0f);
}