[英]Begin Storyboard in a UserControl embedded from behind code in Parent.xaml.cs in Windows Phone Application?
[英]Manipulating Application Bars in Windows Phone 8.1 XAML from Code Behind
這可能是一個微不足道的初學者問題,我已經為Windows和Silverlight應用程序找到了相當多的相關信息,但沒有什么可以直接幫助我。 我正在用C#和XAML編寫Windows Phone 8.1 / WinRT應用程序,我想以編程方式修改在XAML中創建的應用程序欄。 例如,我想在調試版本中包含一個按鈕,使用后面的代碼中的預處理程序指令。
在下面的XAML代碼中,我正在創建一個帶有兩個按鈕的BottomAppBar。 如何創建第二個按鈕(AppBarAddSampleItemsButton),包括代碼背后的所有屬性?
<prism:VisualStateAwarePage.BottomAppBar>
<CommandBar >
<CommandBar.PrimaryCommands>
<AppBarButton x:Uid="AppBarNewItemButton"
Label="New item"
Icon="Add" Command="{Binding GoToAddItemPageCommand}" />
</CommandBar.PrimaryCommands>
<CommandBar.SecondaryCommands>
<AppBarButton x:Uid="AppBarAddSampleItemsButton"
Label="Add sample items"
Command="{Binding GoToAddSampleItemssPageCommand}" />
</CommandBar.SecondaryCommands>
</CommandBar>
</prism:VisualStateAwarePage.BottomAppBar>
下面是一個示例代碼創建AppBarButton在后面的代碼並將其添加到BottomAppBar當前頁面的:
private void AddButtonToAppBar()
{
AppBarButton buttonToAdd = new AppBarButton { Label = "Label", Icon = new SymbolIcon(Symbol.Help) };
buttonToAdd.Click += async (sender, e) => await new MessageDialog("Button clicked").ShowAsync();
// add button to Page's BottoAppBar
(BottomAppBar as CommandBar).PrimaryCommands.Add(buttonToAdd);
}
編輯 - 至於綁定 (再次從我的頭頂,所以你必須檢查這個)這應該可行:
Binding myBind = new Binding();
myBind.Path = new PropertyPath("GoToAddSampleItemssPageCommand");
myBind.Source = DataContext;
buttonToAdd.SetBinding(AppBarButton.CommandProperty, myBind);
有關MSDN上的DataBinding的更多信息。
在Windows Phone開發中心進行了一些挖掘后,我找到了這個頁面: 如何動態更改Windows Phone的應用欄圖標按鈕和菜單項 。 希望能幫助到你!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.