Xaml 如何将弹出按钮附加到MenuFlyUtiItem?
XAML代码:Xaml 如何将弹出按钮附加到MenuFlyUtiItem?,xaml,uwp,c++-cx,Xaml,Uwp,C++ Cx,XAML代码: <Page.TopAppBar> <CommandBar x:Name="bottomAppBar" Padding="10,0,10,0"> <AppBarButton AutomationProperties.Name="Sample Button" AutomationProperties.AutomationId="SampleAppBarButton"
<Page.TopAppBar>
<CommandBar x:Name="bottomAppBar" Padding="10,0,10,0">
<AppBarButton AutomationProperties.Name="Sample Button"
AutomationProperties.AutomationId="SampleAppBarButton"
Click="AppBarButton_Click">
<AppBarButton.Flyout>
<MenuFlyout>
<MenuFlyoutItem x:Name="MuteMenu" Icon="Mute" Text="Mute" Click="MuteMenu_Click">
<FlyoutBase.AttachedFlyout>
<Flyout>
<TextBlock Text="Some text..."/>
</Flyout>
</FlyoutBase.AttachedFlyout>
</MenuFlyoutItem>
</MenuFlyout>
</AppBarButton.Flyout>
</AppBarButton>
</CommandBar>
</Page.TopAppBar>
但ShowAttachedFlyout不工作-单击菜单项时弹出按钮不显示。未报告任何错误
以编程方式创建和附着弹出型按钮也不起作用
目标版本为10.0.18362.0。
Visual Studio 2019(v142)
单击菜单项时弹出按钮不显示
通过测试您的代码,弹出按钮不会出现是因为单击MenuFlyoutItem后,整个MenuFlyout将被隐藏,其中的弹出按钮无法出现
您可以尝试使用包含菜单项级联列表的MenuFlyoutSubItem
<Page.TopAppBar>
<CommandBar x:Name="bottomAppBar" Padding="10,0,10,0">
<AppBarButton AutomationProperties.Name="Sample Button"
AutomationProperties.AutomationId="SampleAppBarButton"
x:Name="MyAppButton" >
<AppBarButton.Flyout>
<MenuFlyout>
<MenuFlyoutSubItem x:Name="MuteMenu" Icon="Mute" Text="Mute">
<MenuFlyoutItem Text="Some Text..."></MenuFlyoutItem>
<MenuFlyoutItem Text="123"></MenuFlyoutItem>
</MenuFlyoutSubItem>
</MenuFlyout>
</AppBarButton.Flyout>
</AppBarButton>
</CommandBar>
</Page.TopAppBar>
也可以添加Button.Flyout并在Button.Flyout中包含菜单Out
<Page.TopAppBar>
<CommandBar x:Name="bottomAppBar" Padding="10,0,10,0">
<AppBarButton x:Name="button" >
<AppBarButton.Flyout>
<Flyout>
<StackPanel>
<Button>
<StackPanel Orientation="Horizontal">
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""></FontIcon>
<TextBlock>Mute</TextBlock>
</StackPanel>
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="Some text..."></MenuFlyoutItem>
</MenuFlyout>
</Button.Flyout>
</Button>
</StackPanel>
</Flyout>
</AppBarButton.Flyout>
</CommandBar>
</Page.TopAppBar>
哑巴
单击菜单项时弹出按钮不显示
通过测试您的代码,弹出按钮不会出现是因为单击MenuFlyoutItem后,整个MenuFlyout将被隐藏,其中的弹出按钮无法出现
您可以尝试使用包含菜单项级联列表的MenuFlyoutSubItem
<Page.TopAppBar>
<CommandBar x:Name="bottomAppBar" Padding="10,0,10,0">
<AppBarButton AutomationProperties.Name="Sample Button"
AutomationProperties.AutomationId="SampleAppBarButton"
x:Name="MyAppButton" >
<AppBarButton.Flyout>
<MenuFlyout>
<MenuFlyoutSubItem x:Name="MuteMenu" Icon="Mute" Text="Mute">
<MenuFlyoutItem Text="Some Text..."></MenuFlyoutItem>
<MenuFlyoutItem Text="123"></MenuFlyoutItem>
</MenuFlyoutSubItem>
</MenuFlyout>
</AppBarButton.Flyout>
</AppBarButton>
</CommandBar>
</Page.TopAppBar>
也可以添加Button.Flyout并在Button.Flyout中包含菜单Out
<Page.TopAppBar>
<CommandBar x:Name="bottomAppBar" Padding="10,0,10,0">
<AppBarButton x:Name="button" >
<AppBarButton.Flyout>
<Flyout>
<StackPanel>
<Button>
<StackPanel Orientation="Horizontal">
<FontIcon FontFamily="Segoe MDL2 Assets" Glyph=""></FontIcon>
<TextBlock>Mute</TextBlock>
</StackPanel>
<Button.Flyout>
<MenuFlyout>
<MenuFlyoutItem Text="Some text..."></MenuFlyoutItem>
</MenuFlyout>
</Button.Flyout>
</Button>
</StackPanel>
</Flyout>
</AppBarButton.Flyout>
</CommandBar>
</Page.TopAppBar>
哑巴
我测试了上述代码,效果很好。当我单击MenuFlyoutItem时,弹出按钮会出现。您的目标版本和visual studio的版本是什么?你能提供一个简单的例子,可以复制给我们测试吗?请看编辑后的答案。我测试了上面的代码,效果很好。当我单击MenuFlyoutItem时,弹出按钮会出现。您的目标版本和visual studio的版本是什么?你能提供一个简单的样本,可以复制给我们测试吗?请看编辑后的答案。