在宽屏的Windows 8 Metro中捕捉ScrollViewer不能捕捉到最后一项 [英] Snapping ScrollViewer in Windows 8 Metro in Wide screens not snapping to the last item

查看:61
本文介绍了在宽屏的Windows 8 Metro中捕捉ScrollViewer不能捕捉到最后一项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已在ScrollViewer中的应用程序中启用了捕捉点,如以下问题所述:使用可绑定的集合启用ScrollViewer Horizo​​ntalSnapPoints

I have enabled snapping points in my app inside a ScrollViewer, as described in this question: Enabling ScrollViewer HorizontalSnapPoints with bindable collection

我遇到的问题是,当我在全高清显示器(1920x1080)中尝试我的应用程序时,每个项目的宽度均为1400像素.到我将滚动条固定在#n-1项中时,我无法滚动到最后一个滚动条,因为它没有对齐...

The problem that I am having is that as I am trying my app in a full HD monitor (1920x1080) and each item is 1400 px width. By the time that I have the scroll snapped in the item #n-1 I can't scroll to the last one, because it doesn't snap...

我要做的黑客是在末尾添加一个透明的假"物品,因此我可以滚动到收藏夹的最后一个物品:

The hack I had to do was to add a "fake" item, transparent at the end, so I can scroll to the last item of my collection:

<Page.Resources>
    <Style x:Key="ItemsControlStyle" TargetType="ItemsControl">
    <Setter Property="ItemsPanel">
        <Setter.Value>
            <ItemsPanelTemplate>
                <VirtualizingStackPanel Orientation="Horizontal"/>
            </ItemsPanelTemplate>
        </Setter.Value>
    </Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="ItemsControl">
                <ScrollViewer Style="{StaticResource HorizontalScrollViewerStyle}" HorizontalSnapPointsType="Mandatory" HorizontalSnapPointsAlignment="Near">
                    <ItemsPresenter />
                </ScrollViewer>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
    </Style>
</Page.Resources>

<ItemsControl Style="{StaticResource ItemsControlStyle}">
    <Border Background="Red" Height="1000" Width="1400"/>
    <Border Background="Blue" Height="1000" Width="1400"/>
    <Border Background="Green" Height="1000" Width="1400"/>
    <Border Background="Yellow" Height="1000" Width="1400"/>
    <Border Background="Magenta" Height="1000" Width="1400"/>
    <Border Background="Transparent" Height="1000" Width="1000" />
</ItemsControl>

我什至会使用此技巧,第二个问题是,我无法从Metro App访问屏幕尺寸,因此我什至无法添加宽度可变的最后一项,具体取决于屏幕解决此问题.有什么建议吗?

The second problem that I'd have even using this hack, is that from a Metro App I don't have access to the screen size, so I couldn't even add a last item with variable width depending on the screen to fix this problem. Any Suggestions?

谢谢!

推荐答案

似乎最好使用Window.Current.Bounds.Width;

It seems that changing programmatically the width of the last item is the best solution, using Window.Current.Bounds.Width;

这篇关于在宽屏的Windows 8 Metro中捕捉ScrollViewer不能捕捉到最后一项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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