【发布时间】:2015-05-12 15:55:27
【问题描述】:
我已经在我的应用程序(Prism)中实现了 mvvm,所以每个逻辑都将出现在 viewmodel 中,所以我不想从后面的代码创建 appbar/commandbar,在 xaml 页面中它不支持多个 appbar/commandbar,我有浏览了许多博客,但我找不到任何满足我需要的解决方案,但我得到了建议,比如在基本页面中使用依赖属性可以完成,但我不知道如何实现它,所以任何人都可以帮助我关于这一点。在此先感谢:)
我的代码低于我在后面的代码中所做的。(xaml 中的第一个应用栏和后面的代码中的第二个)
Xaml:
<storeApps:VisualStateAwarePage.BottomAppBar>
<CommandBar x:Name="firstBar">
<CommandBar.PrimaryCommands>
<AppBarButton Label="Proceed">
<AppBarButton.Icon>
<BitmapIcon UriSource="/Assets/next.png"/>
</AppBarButton.Icon>
</AppBarButton>
</CommandBar.PrimaryCommands>
</CommandBar>
</storeApps:VisualStateAwarePage.BottomAppBar>
CS 代码:
CommandBar secondBar;
public HomePage()
{
this.InitializeComponent();
}
protected override void OnNavigatedTo(NavigationEventArgs e)
{
base.OnNavigatedTo(e);
PrepareAppBars();
}
private void PrepareAppBars()
{
secondBar= new CommandBar();
secondBar.IsOpen = true;
AppBarButton btnHome = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/home.png") } };
btnHome.Label = "Home";
btnHome.IsEnabled = true;
AppBarButton btnWallet = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/wallet.png") } };
btnWallet.Label = "Wallet";
btnWallet.IsEnabled = true;
AppBarButton btnAccount = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/account.png") } };
btnAccount.Label = "Account";
btnAccount.IsEnabled = true;
AppBarButton btnUpdate = new AppBarButton() { Icon = new BitmapIcon() { UriSource = new Uri("ms-appx:///Assets/update.png") } };
btnUpdate.Label = "Update";
btnUpdate.IsEnabled = true;
secondBar.PrimaryCommands.Add(btnHome);
secondBar.PrimaryCommands.Add(btnWallet);
secondBar.PrimaryCommands.Add(btnAccount);
secondBar.PrimaryCommands.Add(btnUpdate);
BottomAppBar = secondBar;
}
private void HomePivot_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
switch (HomePivot.SelectedIndex)
{
case 0:
BottomAppBar = secondBar;
break;
case 1:
BottomAppBar = firstBar;
break;
default:
BottomAppBar = null;
break;
}
}
【问题讨论】:
标签: c# windows-phone-8.1 winrt-xaml