繁体   English   中英

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

[英]UWP: ListBox item not getting selected in an AppBarButton-flyout

我遇到了一个奇怪的问题:当我在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中的相同列表框正在工作:

  <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>

起初,我认为可能是图形问题,但是我尝试将SelectedItem属性绑定到setter。 但是二传手从来没有被叫过。 我只是在这里找不到我的错误。

这里的问题

编辑:

看来是我的机器有问题。 在其他Windows-10上,它的运行就像是一种魅力。

AppBarButton AllowFocusOnInteraction属性设置为true

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

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

或者,如果您的目标是Windows 10周年更新 (1607)内部版本14393或更高版本,但该应用的最低Windows 10版本低于 ,则应检查AllowFocusOnInteraction属性在平台上是否可用。

因此,您无法在XAML中设置AllowFocusOnInteraction属性。 相反,请在代码背后进行操作:

C#代码隐藏的解决方案

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

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

更多信息

您正在运行Windows 10周年更新 (1607),内部版本14393 的新功能

对于大多数应用栏,这是一个改进,但会干扰您的应用栏,因此,当您将内部版本更改为14393而不是10586时,您将需要覆盖默认值。

这是一个博客文章ComboBox,位于附加到AppBarButton的Flyout上,在1607年失去了鼠标输入 它还包含附加的属性实现。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM