我已經在我的應用程序(Prism)中實現了mvvm,所以每個邏輯都會在viewmodel中出現,所以我不想從後面的代碼創建appbar/commandbar,在xaml頁面中它不支持多個appbar/commandbar,我已經離開通過很多博客,但我找不到任何解決方案,但我的基礎頁面中使用依賴項屬性可以完成,但我不知道如何實現它,所以任何人都可以幫助我這個。感謝提前:)如何在Windows Phone 8.1運行時應用程序的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;
}
}
感謝您的回答:)它完美的作品。 – Nambukarthy 2015-05-13 08:58:52