在WinRT XAML应用程序中ListView.CanDragItems允许在使用触摸时仅在一个方向上拖动

时间:2013-03-04 21:57:41

标签: windows-store-apps winrt-xaml

请参阅以下非常基本的XAML。我在触摸模式下在模拟器中运行它。我可以向右或向左拖动项目,但不能向下拖动。使用鼠标模式时它确实很有效。经过一些谷歌搜索我看到了这个线程(http://social.msdn.microsoft.com/Forums/en-US/winappswithcsharp/thread/8bb5e423-4517-448b-89ce-179a978e9e2d/),但它没有帮助我。

<Page
    x:Class="App3.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">
    <Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <ListView Background="AliceBlue" 
            AllowDrop="True" CanDragItems="True" SelectionMode="None"  CanReorderItems="False"
                     IsItemClickEnabled="False" IsSwipeEnabled="True"
                      ScrollViewer.HorizontalScrollBarVisibility="Disabled"
                      ScrollViewer.VerticalScrollBarVisibility="Disabled"
                        Margin="10">
            <ListView.ItemsPanel>
                <ItemsPanelTemplate>
                    <VirtualizingStackPanel Orientation="Horizontal" />
                </ItemsPanelTemplate>
            </ListView.ItemsPanel>
            <ListView.ItemTemplate>
                <DataTemplate>
                    <Border Background="Blue" Width="100" Height="100"/>
                </DataTemplate>
            </ListView.ItemTemplate>
            <x:String>s1</x:String>
            <x:String>s2</x:String>
            <x:String>s3</x:String>
        </ListView>
    </Grid>
</Page>

这是非常基本的东西,很奇怪它对我不起作用。 有人知道任何解决方案或解决方法吗?

由于

梅尔

1 个答案:

答案 0 :(得分:0)

我可能错了但AFAIK使用触摸你只能撕下垂直于滚动方向的物品。您链接到的论坛帖子中也提到过相同的内容。如果设置IsSwipeEnable=False,也会禁用此行为。

如果您希望ListView水平滚动,因为您已经更改了ItemsPanelTemplate的方向,您需要将以下内容添加到ListView

ScrollViewer.HorizontalScrollMode="Enabled"
ScrollViewer.VerticalScrollMode="Disabled"

现在撕下将垂直而不是水平工作,根据您当前的布局,这应该更直观。