在我的场景中,我想为我的所有 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
保持打开状态,并且该按钮显示其全部功能。
最佳答案
是的,我同意这看起来像一个错误。我在代码生成的 route 看到了同样的事情。经过调查,似乎 AppBar.IsOpen 在右键单击或滑动期间切换为 true,但 CommandBar.IsOpen 仍然为 false。这个修复对我有用:
BottomAppBar.Opened += (o, args) => { (this.BottomAppBar.Content as CommandBar).IsOpen = true; };
关于c# - 通过代码添加应用栏(Windows 8.1,C#),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19561300/