C#wpf scrollviewer不像windows store app那样工作

Tot*_*mus 4 c# wpf scroll scrollviewer windows-store-apps

我目前正在使用WPF开发应用程序.而且我不得不注意到与Windows Store App变体相比ScrollViewer功能的差异.

当我在屏幕的边缘和ScrollViewer的边缘时,我想要滑动,以便我离开边缘.我看到Windows桌面或菜单栏(在屏幕的底部).有没有解决方案来防止这种滚动行为发生?当你滚动到屏幕的边缘然后被撞回来看到下面的一些Windows平台时,它相当烦人(而且很丑!).Windows应用程序ScrollViewer中已修复此问题.

我尝试覆盖ScrollChanged并检查fe horizontalOffset == 0 && horizontalChange < 0是否返回,如果是这种情况.但这种检查似乎不起作用(从那以后它可能已经太晚了).而我似乎无法找到Windows应用商店应用程序修复此问题的方式.

在此输入图像描述

也许你们有个主意吗?


编辑: .NET 4.5.1中的WPF项目的再现

这段XAML在WPF中重新创建了我的问题.但是,在Windows应用商店应用中,问题似乎不存在.

滚动到和/或覆盖应用程序边缘时,如何防止此行为?

<Window x:Class="WpfApplication1.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="MainWindow" Height="350" Width="525" ResizeMode="NoResize" WindowState="Maximized" WindowStyle="None">
    <Grid>
        <ScrollViewer HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" PanningMode="Both">
            <Rectangle Height="2500" Stroke="Black" Width="3500" HorizontalAlignment="Left" VerticalAlignment="Top">
                <Rectangle.Fill>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0,0.5">
                        <GradientStop Color="#FF00FF68" Offset="0"/>
                        <GradientStop Color="Red" Offset="1"/>
                        <GradientStop Color="#FF95FF00" Offset="0.506"/>
                    </LinearGradientBrush>
                </Rectangle.Fill>
            </Rectangle>
        </ScrollViewer>

    </Grid>
</Window>
Run Code Online (Sandbox Code Playgroud)

Eti*_*heu 5

这是与滚动相关的默认Windows 8行为.当您点击可滚动视图的边缘时,您的整个应用都会"反弹".这种情况发生在每一个案例中,并且是系统动画的一部分.例如,您可以在很长的文件夹列表中的Windows资源管理器中看到它.这只发生在滚动触摸时,如果我没记错的话,在非全屏应用程序上.我目前无法访问Windows 8计算机来测试此声明,并且很可能无法禁用此行为.

Modern环境是一个完全独立的应用程序环境,并且根本不以相同的方式处理触摸手势.这就是WinRT应用程序中不存在此行为的原因.

编辑:此效果称为操纵边界反馈.当操纵事件超出其容器的限制时触发.您可以禁用它覆盖OnManipulationBoundaryFeedback(ManipulationBoundaryFeedbackEventArgs)受影响的方法,UIElement如下所示:

class NoTouchFeedbackWindow : Window
{
    protected override void OnManipulationBoundaryFeedback(ManipulationBoundaryFeedbackEventArgs e)
    {
        e.Handled = true;
    }
}
Run Code Online (Sandbox Code Playgroud)

这也可以直接在您的ScrollViewer或链上的任何控件上完成.

您可以在以下位置找到有关此行为的更多信息

希望这可以解决您的问题.