C#WPF的ScrollViewer不能正常工作,如Windows商店应用 [英] C# wpf scrollviewer not working like windows store app

查看:804
本文介绍了C#WPF的ScrollViewer不能正常工作,如Windows商店应用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在使用WPF应用程序。
和我不能不帮注意到相比,Windows应用商店应用程序变体的ScrollViewer功能的差异。



当我在的边缘屏幕和一个ScrollViewer中的边缘,我想滑动,这样我会移到远离边缘。我看到(在屏幕的底部时)在Windows桌面或菜单栏。
是有一个解决方案,以防止发生此滚动行为?这是相当恼人(和丑陋!)当你的滚动,直到屏幕的边缘,然后得到撞回来,去看了一下windows平台的下方。
这种行为被固定在Windows Store应用的ScrollViewer ..



我试图覆盖 ScrollChanged 和检查是否FE horizo​​ntalOffset == 0安培;&安培; horizo​​ntalChange< 0 和返回,如果是这种情况。但这种检查似乎没有工作(因为那么它可能已经太晚了)。
和我似乎无法找到了Windows商店应用有固定的这个





也许你们有一个想法?






编辑:
复制在.NET 4.5.1



WPF项目

这一块XAML的重新创建我的WPF问题。但是在Windows Store应用问题似乎并不存在。



如何防止这种行为滚动和/或在我的应用程序的边缘时?

 <窗口x:类=WpfApplication1.MainWindow
的xmlns =http://schemas.microsoft.com / WinFX的/ 2006 / XAML /演示
的xmlns:X =http://schemas.microsoft.com/winfx/2006/xaml
标题=主窗口HEIGHT =350WIDTH = 525ResizeMode =NoResize的WindowState =最大化WindowStyle =无>
<网格和GT;
<的ScrollViewer Horizo​​ntalScrollBarVisibility =隐藏VerticalScrollBarVisibility =隐藏PanningMode =两者>
<矩形高度=2500行程=黑WIDTH =3500的Horizo​​ntalAlignment =左VerticalAlignment =评出的>
< Rectangle.Fill>
<一个LinearGradientBrush终点=0.5,1StartPoint可以=0,0.5>
将;渐变停止颜色=#FF00FF68偏移=0/>
<渐变停止颜色=红偏移量=1/>
<渐变停止颜色=#FF95FF00偏移量=0.506/>
< /一个LinearGradientBrush>
< /Rectangle.Fill>
< /矩形>
< /&的ScrollViewer GT;

< /网格和GT;
< /窗GT;


解决方案

这是关系到滚动默认的Windows 8的行为。整个应用程序将反弹创下了滚动能够视图的边缘的时候。这种情况发生在每一个情况下,是在系统的动画的一部分。你可以看到它,例如,在Windows资源管理器文件夹中的一个长长的清单时。这只能通过触摸和滚动的时候,如果我没有记错,在非全屏应用程序发生。我目前还没有进入到Windows 8机器来测试这种说法<击>并且有很可能是没有办法禁用此行为



现代环境是一个完全独立的应用环境和以同样的方式不处理触摸手势在所有。这就是为什么这种行为并不在WinRT的应用程序存在



修改:这种效应被称为操纵边界反馈。当操纵事件超出其容器的极限它触发。您可以禁用它覆盖 OnManipulationBoundaryFeedback在(ManipulationBoundaryFeedbackEventArgs)方法对受影响的UIElement 像这样:

 类NoTouchFeedbackWindow:窗口
{
保护覆盖无效OnManipulationBoundaryFeedback在(ManipulationBoundaryFeedbackEventArgs E)
{
é。办理= TRUE;
}
}

这也可以直接在您的ScrollViewer或完成。控制了链



您可以找到有关此行为的详细信息:





我们希望,这应该解决您的问题。


I'm currently working on an application using WPF. And I can't but help to notice the difference in ScrollViewer functionality compared to the Windows Store App variant.

When I'm at the edge of the screen and the edge of a ScrollViewer and I want to slide so that I'd move away from the edge. I see the windows desktop or menubar (when at the bottom of the screen). Is there a solution to prevent this scroll behaviour from happening? It is rather annoying (and ugly!) when your scrolling till the edge of the screen and then get bumped back and see a bit of the windows platform underneath. This behaviour is fixed in the Windows Store App ScrollViewer..

I tried overwriting the ScrollChanged and checking if f.e. horizontalOffset == 0 && horizontalChange < 0 and return if this is the case. But this check doesn't seem to work (since then it's probably already too late). And I can't seem to find the way Windows Store Apps have fixed this.

Perhaps you guys have an idea?


EDIT: Reproduction for WPF projects in .NET 4.5.1

This piece of XAML re-creates my problem in WPF. However in Windows Store App the problem doesn't seem to exist.

How can I prevent this behaviour when scrolling to and/or over the edges of my application?

<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>

解决方案

This is the default Windows 8 behavior related to scrolling. Your entire app will "bounce" when hitting the edge of a scroll-able view. This happens in every single cases and is part of the system animations. You can see it, for instance, in the Windows Explorer when in a long list of folders. This only happens when scrolling through touch and, if I remember correctly, on non full-screen applications. I do not currently have access to a Windows 8 machine to test this claim and there might very well be no way to disable this behavior.

The Modern environment is a completely separate application environment and does not handle touch gestures in the same way at all. This is why this behavior does not exists in a WinRT application.

EDIT : This effect is called the Manipulation Boundary Feedback. It triggers when a manipulation event goes beyond the limits of its container. You can disable it overriding the OnManipulationBoundaryFeedback(ManipulationBoundaryFeedbackEventArgs) method on the affected UIElement like so:

class NoTouchFeedbackWindow : Window
{
    protected override void OnManipulationBoundaryFeedback(ManipulationBoundaryFeedbackEventArgs e)
    {
        e.Handled = true;
    }
}

This could also be done directly on your ScrollViewer or any control up the chain.

You can find more information about this behavior on:

Hopefully, this should solve your issue.

这篇关于C#WPF的ScrollViewer不能正常工作,如Windows商店应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆