xaml - 如何将 Flyout 附加到 MenuFlyoutItem?
问题描述
XAML 代码:
<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>
C++/CX:
void App2::DirectXPage::MuteMenu_Click(Platform::Object^ sender, Windows::UI::Xaml::RoutedEventArgs^ e)
{
FlyoutBase::ShowAttachedFlyout((FrameworkElement^)sender);
}
但是 ShowAttachedFlyout 不起作用 - 当我单击菜单项时没有出现弹出窗口。没有报告错误。
以编程方式创建和附加弹出窗口也不起作用。
目标版本是 10.0.18362.0。Visual Studio 2019 (v142)。
解决方案
单击菜单项时未出现弹出窗口
通过测试你的代码,flyout没有出现是因为点击MenuFlyoutItem后,整个MenuFlyout会被隐藏,里面的Flyout不能出现。
您可以尝试使用包含菜单项级联列表的 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 并将 menuFlyout 包含在 Button.Flyout 中。
<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>
推荐阅读
- vue.js - 动态更新 v-combobox 项目列表
- firebase - Flutter - 创建可共享的个人资料链接
- jupyter-notebook - Jupyter notebook 在渲染 pybullet-gym 环境后崩溃
- extjs - 网格列标题分组不正确
- azure-devops - Azure Devops Release XML 变量未被替换
- android - WorkManager 在某些三星设备上抛出 SecurityException
- python-3.x - python中的多重处理
- javascript - 正文点击元素原生js
- awk - 使用 awk 仅从第一个实例获取信息
- c++ - 将自定义命令行参数传递给 Rust 测试