[英]UWP CommandBar SecondaryCommand collides with AppBarButton Flyout
[英]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
。
<AppBarButton x:Name="myAppBarButton"
AllowFocusOnInteraction="True">
...
</AppBarButton>
或者,如果您的目標是Windows 10周年更新 (1607)內部版本14393或更高版本,但該應用的最低Windows 10版本低於 ,則應檢查AllowFocusOnInteraction
屬性在平台上是否可用。
因此,您無法在XAML中設置AllowFocusOnInteraction
屬性。 相反,請在代碼背后進行操作:
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.