私はアプリケーション(Prism)にmvvmを実装したので、すべてのロジックがviewmodelに含まれるので、コードビハインドからアプリバー/コマンドバーを作成したくありません。xamlページでは、複数のアプリバー/コマンドバーをサポートしていません。ブログですが、必要な解決策が見つかりませんでしたが、ベースページで依存関係プロパティを使用するなどの提案がありましたが、実装方法がわからないので、誰かがこれについて助けてくれますか?前もって感謝します :)
私のコードは、コードビハインドで行ったことを下回っています(xamlの最初のアプリバーとコードビハインドの2番目)
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;
}
}
同じ要件があります。このソリューションを試してみます。XAMLを使用してボタンを定義し、ViewModel(MVVMパターン)を使用してこれらのボタンの表示を制御できます。さまざまなグループでボタンを作成します。ビューモデルでプロパティを定義します。このプロパティはボタンのさまざまなグループを表示するために使用されるため、XAMLでそのプロパティをバインドする必要があります。この複数のAppBar / CommandBarsを確認してください
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加