在我的方案中,我想爲我的所有Windows 8.1應用程序頁面編寫BasePage
。 在此BasePage
中應該創建TopAppBar
。按代碼添加AppBar(Windows 8.1,C#)
其實我有:
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);
}
的strage行爲是closeBtn
不會在TopAppBar
顯示,直到我點擊我的鼠標右鍵兩次。
意思是我第一次點擊右鍵 - >出現TopAppBar
,但裏面沒有按鈕。
然後我再次單擊右鍵 - >TopAppBar
保持打開狀態,並且該按鈕顯示其全部功能。
似乎是一個錯誤。在WPF的美好時代,我會嘗試使父控制無效。作爲測試,您可以在添加新按鈕時切換appbar的可見性。或者,重新創建整個酒吧。 – WiredPrairie