我有一个可能是愚蠢的疑问,但我真的不知道如何解决这个问题。
我有一个复杂的用户界面,里面有很多项目(一个 SplitView 里面有其他东西,然后是一个包含页面的框架,我有一个网格,最后是我的 CommandBar)。
当我点击“...”按钮时,CommandBar 向窗口顶部打开,它实际上还覆盖了其父 Page 所在的 Frame 的部分 UI 外部位于(我不知道这怎么可能)。
我尝试将 CommandBar、父网格、页面等的 VerticalAlignment 属性设置为 Top,但 CommandBar 仍然向屏幕的顶部打开。
有没有办法让它向底部打开,就像内置天气或照片应用程序中的 CommandBar 一样?我在这里缺少设置/属性吗?
感谢您的帮助!
塞尔吉奥
编辑:为了清楚起见,我页面的基本结构是这样的:
RootContent > ... > Frame > Page > Grid > CommandBar
我不能将 CommandBar 放在 Page.TopAppBar 中,就好像我这样做一样,CommandBar 被放置在我的 Page 的 外面 并覆盖了我的 UI 的顶部。我需要将 CommandBar 放置在页面内部。
最佳答案
CommandBar 依靠 VisualStates 来控制这部分尺寸和动画,这使得使用自定义视觉状态管理器拦截状态更改调用并将所有 OpenUp 调用替换为 OpenDown 调用变得容易。
public class OpenDownCommandBarVisualStateManager : VisualStateManager
{
protected override bool GoToStateCore(Control control, FrameworkElement templateRoot, string stateName, VisualStateGroup group, VisualState state, bool useTransitions)
{
//replace OpenUp state change with OpenDown one and continue as normal
if(!string.IsNullOrWhiteSpace(stateName) && stateName.EndsWith("OpenUp"))
{
stateName = stateName.Substring(0, stateName.Length - 6) + "OpenDown";
}
return base.GoToStateCore(control, templateRoot, stateName, group, state, useTransitions);
}
}
public class OpenDownCommandBar : CommandBar
{
public OpenDownCommandBar()
{
}
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();
var layoutRoot = GetTemplateChild("LayoutRoot") as Grid;
if(layoutRoot != null)
{
VisualStateManager.SetCustomVisualStateManager(layoutRoot, new OpenDownCommandBarVisualStateManager());
}
}
}
然后只需使用新的 OpenDownCommandBar 而不是普通的。
<myControls:OpenDownCommandBar>...</myControls:OpenDownCommandBar>
关于c# - 如何使 CommandBar 打开到屏幕底部?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33290361/