c# - 以编程方式选择 NavigationView 溢出列表中的项目
问题描述
当我尝试以编程方式选择 a 的“溢出列表”中的项目时NavigationView
,出现以下错误:
参数不正确。
容器'
下图是一个示例,我尝试以编程方式选择菜单项 3:
var nextItem = dataSource.indexOf(menuItem3);
NavView.SelectedItem = nextItem;
选择未溢出的项目时效果很好。
解决方案
参数不正确。容器'
为了解释这种行为,我们需要检查Generic.xaml文件NavigationView
中的样式。
<Button
x:Name="TopNavOverflowButton"
Grid.Column="4"
Content="More"
Style="{StaticResource NavigationViewOverflowButtonStyleWhenPaneOnTop}"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=TemplateSettings.OverflowButtonVisibility}">
<Button.Flyout>
<Flyout Placement="Bottom">
<Flyout.FlyoutPresenterStyle>
<Style TargetType="FlyoutPresenter">
<Setter Property="Padding" Value="0,8" />
<!-- Set negative top margin to make the flyout align exactly with the button -->
<Setter Property="Margin" Value="0,-4,0,0" />
</Style>
</Flyout.FlyoutPresenterStyle>
<NavigationViewList x:Name="TopNavMenuItemsOverflowHost" ItemTemplate="{TemplateBinding MenuItemTemplate}" ItemTemplateSelector="{TemplateBinding MenuItemTemplateSelector}" ItemContainerStyle="{TemplateBinding MenuItemContainerStyle}" ItemContainerStyleSelector="{TemplateBinding MenuItemContainerStyleSelector}" SingleSelectionFollowsFocus="False" IsItemClickEnabled="True">
<ListView.ItemContainerTransitions>
<TransitionCollection />
</ListView.ItemContainerTransitions>
</NavigationViewList>
</Flyout>
</Button.Flyout>
</Button>
如您所见,更多项目存储在TopNavMenuItemsOverflowHost NavigationViewList
中。它的容器是Flyout
. Flyout 是延迟加载控制。如果它没有弹出,它的内容将不会被加载。这就是容器丢失的原因。
我认为在TopNavMenuItemsOverflowHost
. 如果您想正确选择项目,请确保足够的窗口宽度可以使所有项目显示在NavigationView
.
推荐阅读
- sql - SQL 透视值列和位列
- google-sheets - 如何在谷歌表中旋转余额
- asp.net-core - 重定向在 DNS 指向另一台主机的网站上不起作用
- amazon-web-services - 使用 CloudFormation 时,AWS Lambda 函数缺少 websocket 网关的触发器
- python - 认证不适用于 pycharm。苹果系统
- javascript - 区分 JavaScript Try/Catch 中的 API (Apex) 异常类型
- powershell - 如何在 VSCode 中设置自定义 powershell 安装目录
- python - 无法加载使用 Igor pro 保存的 Python hdf 文件
- sql - 处理模型表中 expires_in 数据的最佳方法是什么
- javascript - 在 Discord.js V13 中发送贴纸