![](/img/trans.png)
[英]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.