如何在打开时阻止AppBar捕获触摸活动?

时间:2013-01-22 02:14:22

标签: windows-8 winrt-xaml

我提前道歉,这个很难解释。

我有一个GridView,可以选择。进行选择后,通过将IsOpen和IsSticky设置为true来显示底部AppBar。这很好用。

然而,当AppBar在第一次选择之后出现时,它会捕获任何触摸活动,然后在任何触摸到AppBar外部区域后将其释放,但该触摸手势会被吸收。我最终触摸屏幕两次以执行第二次选择。

在Windows 8的开始屏幕中,您可以无缝地逐个选择多个图块。出现的底栏不会干扰后续的触摸手势。但在我的应用程序中,条形图捕获了第一个手势,最后我选择了第二个图块两次。这让我的应用感到反应迟钝。

我该如何解决这个问题?

要复制此内容:

1)在Visual Studio 2012中的Windows应用商店下启动一个新的“网格应用(XAML)”。

2)在GroupedItemsPage.xaml中,将以下XAML添加到其中:

<Page.BottomAppBar>
    <AppBar>
        <Button Content="X"/>
    </AppBar>
</Page.BottomAppBar>

3)使用x找到GridView:Name =“itemGridView”并设置其 SelectionMode =“Extended” IsSwipeEnabled =“true”

<GridView
    x:Name="itemGridView"
    AutomationProperties.AutomationId="ItemGridView"
    AutomationProperties.Name="Grouped Items"
    Grid.RowSpan="2"
    Padding="116,137,40,46"
    ItemsSource="{Binding Source={StaticResource groupedItemsViewSource}}"
    SelectionMode="Extended"
    IsSwipeEnabled="true"
    IsItemClickEnabled="True"
    ItemClick="ItemView_ItemClick">

4)在代码隐藏文件中添加以下代码:

public GroupedItemsPage()
    {
        this.InitializeComponent();

        itemGridView.SelectionChanged += ItemGridViewOnSelectionChanged;
    }

    private void ItemGridViewOnSelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        if (itemGridView.SelectedItems.Count > 0)
        {
            this.BottomAppBar.IsOpen = true;
            this.BottomAppBar.IsSticky = true;
        }
        else
        {
            this.BottomAppBar.IsSticky = false;
            this.BottomAppBar.IsOpen = false;
        }
    }

5)运行它并注意第一次选择后出现的应用栏,但是第二个用于选择第二个图块的手势将被吸收。

1 个答案:

答案 0 :(得分:1)

信不信由解决方案非常简单。您必须更改设置BottomAppBar.IsOpenBottomAppBar.IsSticky的方式的顺序:

private void ItemGridViewOnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
    if (itemGridView.SelectedItems.Count > 0)
    {
        //this.BottomAppBar.IsOpen = true;
        //this.BottomAppBar.IsSticky = true;

        // must be done in this order for the app bar to work correctly
        this.BottomAppBar.IsSticky = true;
        this.BottomAppBar.IsOpen = true;
    }
    else
    {
        //this.BottomAppBar.IsSticky = false;
        //this.BottomAppBar.IsOpen = false;

        // I have a note in my code to use the following order,
        // but ordering for this doesn't seem to matter.
        this.BottomAppBar.IsOpen = false;
        this.BottomAppBar.IsSticky = false;
    }
}

我不确定为什么订单很重要,但确实如此。

相关问题