UWP ListView ScrollViewer-重置缩放(系数)

UWP ListView ScrollViewer-重置缩放(系数),listview,scrollview,uwp-xaml,bitmapimage,Listview,Scrollview,Uwp Xaml,Bitmapimage,我的ListView保存位图图像,我想允许放大这些图像 如果我使用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:l

我的ListView保存位图图像,我想允许放大这些图像

如果我使用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的回答,您应该从列表视图中找到对象,然后您可以使用该方法的
zoomFactor
参数重置其属性

首先,您可以在助手类中使用以下方法从ListView中找到对象

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;
    }
}
公共静态类UIHelper
{
公共静态子元素FindVisualChild(此DependencyObject obj)
其中ChildElement:DependencyObject
{
for(int i=0;i
然后,您可以获取该对象并在UserControl的代码中重置它

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);
}
private void reset按钮\u单击(对象发送者,路由目标)
{
var scrollViewer=PdfListView.FindVisualChild();
//将“视图”更改为“垂直偏移”,并将缩放因子设置为1。
//默认缩放因子为1.0,其中1.0表示没有其他缩放
scrollViewer.ChangeView(0,scrollViewer.VerticalOffset,1.0f);
}