首页 文章

UWP:未在AppBarButton-flyout中选择ListBox项

提问于
浏览
0

我遇到了一个奇怪的问题:当我在AppBarButton-Flyout中包含一个ListBox时:

<Page.TopAppBar>
            <CommandBar>
                <AppBarButton Icon="Add">
                <AppBarButton.Flyout>
<Flyout x:Name="TestFlyout">
                        <ListBox>
                            <ListBoxItem Content="A" />
                            <ListBoxItem Content="C" />
                            <ListBoxItem Content="D" />
                            <ListBoxItem Content="e" />
                            <ListBoxItem Content="F" />
                            <ListBoxItem Content="A" />

                        </ListBox>
                    </Flyout>
                </AppBarButton.Flyout>
            </AppBarButton>
            </CommandBar>
        </Page.TopAppBar>

未选中项目(应以蓝色突出显示) . Button Flyout中的同一个Listbox正在工作:

<Button Content="Click me" IsEnabled="True">
            <Button.Flyout>
                <Flyout>
                    <ListBox>
                        <ListBoxItem Content="A" />
                        <ListBoxItem Content="C" />
                        <ListBoxItem Content="D" />
                        <ListBoxItem Content="e" />
                        <ListBoxItem Content="F" />
                        <ListBoxItem Content="A" />

                    </ListBox>
                </Flyout>
            </Button.Flyout>
        </Button>

起初我想也许是's a graphical issue, but I'已经试图将 SelectedItem 属性绑定到一个解决者 . 但是从不打电话给那个二传手 . 我在这里找不到我的错误 .

Here the issue

Edit:

似乎是我的机器的问题 . 在其他Windows-10上,它的工作就像一个魅力 .

1 回答

  • 1

    AppBarButton 上将 AllowFocusOnInteraction 属性设置为 true .

    XAML中的解决方案(适用于Windows 10,版本1607)

    <AppBarButton x:Name="myAppBarButton"
                  AllowFocusOnInteraction="True">
    ...
    </AppBarButton>
    

    或者如果您的目标是 Windows 10 Anniversary update (1607)内部版本为14393或更高版本,但应用程序为 minimum Windows 10 version is lower ,则应检查平台上是否有 AllowFocusOnInteraction 属性 .

    因此,您无法在XAML中设置 AllowFocusOnInteraction 属性 . 相反,在代码隐藏中执行此操作:

    C#代码隐藏中的解决方案

    if (Windows.Foundation.Metadata.ApiInformation.IsPropertyPresent("Windows.UI.Xaml.FrameworkElement", "AllowFocusOnInteraction"))
         myAppBarButton.AllowFocusOnInteraction = true;
    

    您还可以将其包装到附加属性中,即使在所有Windows 10版本上也可以在XAML中使用 .

    更多信息

    您正在 Windows 10 Anniversary update (1607),构建14393上遇到新功能 .

    这是大多数应用栏使用的改进,但会干扰你的,因此当你将构建更改为14393而不是10586时,你需要覆盖默认值 .

    这是一篇博文ComboBox on a Flyout attached to an AppBarButton loses mouse input on 1607 . 它还包含附加的属性实现 .

相关问题