禁用水平滚动时为什么GridView选择停止工作?

时间:2013-04-08 19:37:24

标签: c# windows-store-apps

更新1 https://bitbucket.org/vmrocha/gridview-issue/src

更新2 :使用鼠标选择工作,不起作用的选择是使用触摸的选择。

我编写了以下代码,但是当我将水平滚动设置为“已禁用”时,GridView选择停止工作。

XAML:

<Page
x:Class="App1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App1"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">

<Page.Resources>

    <ItemsPanelTemplate x:Key="itemsPanelTemplate">
        <StackPanel />
    </ItemsPanelTemplate>

    <DataTemplate x:Key="dataTemplate">
        <Grid Width="100" Height="100">
            <TextBlock Text="{Binding}" />
        </Grid>
    </DataTemplate>

    <Style TargetType="GridView">
        <Setter Property="SelectionMode" Value="Multiple" />
        <Setter Property="IsItemClickEnabled" Value="True" />
    </Style>

</Page.Resources>

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <ScrollViewer HorizontalScrollMode="Auto"
                  VerticalScrollMode="Disabled">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
            </Grid.ColumnDefinitions>
            <!--The selection here does not work-->
            <GridView x:Name="gridView1" ItemsSource="{Binding Items1}"
                      ItemsPanel="{StaticResource itemsPanelTemplate}"
                      ItemTemplate="{StaticResource dataTemplate}"
                      ScrollViewer.HorizontalScrollMode="Disabled">
            </GridView>
            <GridView x:Name="gridView2" ItemsSource="{Binding Items2}" Grid.Column="1"
                      ItemsPanel="{StaticResource itemsPanelTemplate}"
                      ItemTemplate="{StaticResource dataTemplate}">
            </GridView>
        </Grid>
    </ScrollViewer>
</Grid>

C#代码:

    public MainPage()
    {
        this.InitializeComponent();

        this.Items1 = new ObservableCollection<string>();
        this.Items2 = new ObservableCollection<string>();

        this.PopulateItems();

        this.DataContext = this;
    }

    private void PopulateItems()
    {
        this.Items1.Add("String 1");
        this.Items1.Add("String 1");
        this.Items1.Add("String 1");
        this.Items1.Add("String 1");
        this.Items1.Add("String 1");
        this.Items1.Add("String 1");
        this.Items1.Add("String 1");

        this.Items2.Add("String 2");
        this.Items2.Add("String 2");
        this.Items2.Add("String 2");
        this.Items2.Add("String 2");
        this.Items2.Add("String 2");
        this.Items2.Add("String 2");
        this.Items2.Add("String 2");
    }

如果我删除了ScrollViewer.Horizo​​ntalScrollMode =“Disabled”这一行,则选择会再次开始工作。

有什么想法吗?

0 个答案:

没有答案