【问题标题】:How can I stop the AppBar from capturing touch activity when opened?如何在打开时阻止 AppBar 捕获触摸活动?
【发布时间】:2013-01-22 02:14:22
【问题描述】:

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

我有一个 GridView,里面装满了可选择的图块。进行选择时,通过将 IsOpen 和 IsSticky 设置为 true,将显示底部 AppBar。这工作正常。

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

在Windows 8的开始画面中,您可以无缝选择多个磁贴。出现的底部栏不会干扰后续的触摸手势。但是在我的应用程序中,该栏捕获了第一个手势,我最终选择了第二个图块两次。这让我的应用感觉反应迟钝。

我该如何解决这个问题?

复制这个:

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

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

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

3) 找到 x:Name="itemGridView" 的 GridView 并设置其 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) 运行它并注意在第一次选择之后出现应用栏,但随后您选择第二个图块的第二个手势被吸收了。

【问题讨论】:

  • 您可以发布 GridView 和 App Bar xaml 吗?无需发布任何一个的子元素。我想看看您在 xaml 中使用的选项。另外,您能否发布设置应用栏的 IsOpen 和 IsSticky 字段的代码隐藏?
  • @chuex 我添加了一个示例。使用 Visual Studio 中的标准 Grid 应用程序非常基础。

标签: windows-8 winrt-xaml


【解决方案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;
    }
}

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

【讨论】:

  • 难以置信!好尴尬!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-01-27
  • 1970-01-01
  • 2015-02-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多