gpt4 book ai didi

c# - 通过代码添加 AppBar(Windows 8.1,C#)

转载 作者:太空宇宙 更新时间:2023-11-03 10:55:48 25 4
gpt4 key购买 nike

在我的场景中,我想为我所有的 Windows 8.1 应用程序页面编写一个 BasePage。在此 BasePage 中,应该创建一个 TopAppBar

其实我有:

public CommandBar TopCommandBar
{
get
{
// Check if a TopAppBar exists
if (this.TopAppBar != null) return this.TopAppBar.Content as CommandBar;

var appBar = new AppBar();
this.TopAppBar = appBar;
var top = this.TopAppBar.Content as CommandBar;
if (top == null)
{
topCommandBar = new CommandBar();
this.TopAppBar.Content = topCommandBar;
}
return this.TopAppBar.Content as CommandBar;
}
}

这段代码运行良好。但稍后在我的 BaseClass 中我想添加一个 AppBarButton

if (ShowCloseButton)
{
var closeBtn = new AppBarButton();
closeBtn.Icon = new SymbolIcon(Symbol.Clear);
closeBtn.Label = "Close";
closeBtn.Click += closeBtn_Click;
this.TopCommandBar.PrimaryCommands.Insert(0, closeBtn);
}

策略行为是 closeBtn 不会显示在 TopAppBar 中,直到我单击鼠标右键两次。

表示我第一次单击右键时 --> TopAppBar 出现但里面没有按钮。

然后我再次单击右键 --> TopAppBar 保持打开状态并且按钮显示其全部功能。

最佳答案

是的,我同意这看起来像是一个错误。我在代码生成的路由中看到了同样的事情。经过调查,AppBar.IsOpen 似乎在右键单击或滑动期间切换为 true,但 CommandBar.IsOpen 仍然为 false。此修复对我有用:

BottomAppBar.Opened += (o, args) => { (this.BottomAppBar.Content as CommandBar).IsOpen = true; };

关于c# - 通过代码添加 AppBar(Windows 8.1,C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19561300/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com