繁体   English   中英

在ItemsControl中反转ScrollViewer的滚动方向

[英]Invert scroll direction of ScrollViewer in an ItemsControl

无论出于什么原因,我都有一个在Y坐标上翻转过的ItemsControl ,并且在其中有ScrollViewer

<ItemsControl ...>

    ...

    <ItemsControl.LayoutTransform>
        <ScaleTransform ScaleY="-1" />
    </ItemsControl.LayoutTransform>

    <ItemsControl.Template>
        <ControlTemplate>
            <ScrollViewer Focusable="False" Padding="{TemplateBinding Control.Padding}">
                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}" />
            </ScrollViewer>
        </ControlTemplate>
    </ItemsControl.Template>

    ...

</ItemsControl>

每个DataTemplate都有类似的转换,因此文本看起来正确。

这造成的一个问题是滚动反转。 无论如何,有没有反转滚动方向? 或以某种方式自己计算,而不是默认的滚动行为。 我该如何实现?

如果将ItemsControl的LayoutTransform移到ItemsPresenter怎么办? 然后,scrollviewer在翻转之外。

<ItemsControl ...>
    ...
    <ItemsControl.Template>
        <ControlTemplate>
            <ScrollViewer Focusable="False" Padding="{TemplateBinding Control.Padding}">
                <ItemsPresenter SnapsToDevicePixels="{TemplateBinding UIElement.SnapsToDevicePixels}">
                    <ItemsPresenter.LayoutTransform>
                        <ScaleTransform ScaleY="-1" />
                    </ItemsPresenter.LayoutTransform>
                </ItemsPresenter>
            </ScrollViewer>
        </ControlTemplate>
    </ItemsControl.Template>
    ...
</ItemsControl>

好的...对您不起作用。

如何制作自己的scrollviewer并覆盖OnPreviewMouseWheel以反转鼠标滚轮的增量更改?

public class ScrollViewerInvert : System.Windows.Controls.ScrollViewer
{
    protected override void OnPreviewMouseWheel(MouseWheelEventArgs e)
    {
        if (e.Delta != 0)
            e = new MouseWheelEventArgs(e.MouseDevice, e.Timestamp, e.Delta * -1);
        base.OnPreviewMouseWheel(e);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM