を変更するとき、私はそれがすべての罰金です私のメインウィンドウでTabControlのと作業LeftWindowCommandMahApps変更LeftWindowCommands項目タブ
<Controls:MetroWindow.LeftWindowCommands>
<Controls:WindowCommands >
<Button x:FieldModifier="public" x:Name="btnOpenBanMenu" Click="btnOpenBanMenu_Click">
<StackPanel Orientation="Horizontal">
<Rectangle Width="20"
Height="20"
Fill="{Binding Foreground, RelativeSource={RelativeSource AncestorType={x:Type Button}}}">
<Rectangle.OpacityMask>
<VisualBrush Stretch="Fill" Visual="{StaticResource bans}" />
</Rectangle.OpacityMask>
</Rectangle>
<TextBlock Margin="4 0 0 0"
VerticalAlignment="Center"
Text="Bans"/>
</StackPanel>
</Button>
</Controls:WindowCommands>
</Controls:MetroWindow.LeftWindowCommands>
を持っています。 しかし、LeftWindowCommandを "Sub-Menu-Bar"として使用したいので、選択したTabを変更した場合、LeftWindowCommands-Barは項目やボタンの背後にあるアクションも変更する必要があります。 私は視界で遊んだことがありますが、それは私が望むものではありません。
より良く理解するために:
あなたはアイテム "プレゼント、Losung、Songrequest" を参照してください。 これらのアイテムは私のTabControlの中にあります。
そして今、私は別のタブを選んでプレゼントをするときに、「サブメニュー」 - 項目(画像に記載)を変更したいと思います。
誰かが私の手引きをしてくれますか?
EDIT2:最後にMVVMで動作しますが、LeftWindowCommandsをバインドする方法はまだわかりません。
MainModel:
class MainModel
{
public string Header { get; set; }
public MahApps.Metro.Controls.MetroContentControl Content { get; set; }
public MahApps.Metro.Controls.WindowCommands LeftWindowCommands { get; set; }
}
MainViewModel:
class MainViewModel : BaseViewModel
{
private ObservableCollection<Model.MainModel> _tabItems;
public ObservableCollection<Model.MainModel> tabItems
{
get { return _tabItems; }
set
{
_tabItems = value;
OnPropertyChanged("tabItems");
}
}
public MainViewModel()
{
_tabItems = new ObservableCollection<Model.MainModel>()
{
new Model.MainModel
{
Header = "Giveaway",
Content = new Controls.ucGiveaway(),
LeftWindowCommands = LeftWindowCommandsGiveaway()
},
... etc
};
}
private MahApps.Metro.Controls.WindowCommands LeftWindowCommandsGiveaway()
{
MahApps.Metro.Controls.WindowCommands command = new MahApps.Metro.Controls.WindowCommands();
command.Items.Add(
new Button { Content = "MyButton #1", Foreground = Brushes.Red });
return command;
}
}
のDataContext:
<Controls:MetroWindow.DataContext>
<ViewModels:MainViewModel/>
</Controls:MetroWindow.DataContext>
タブコントロール:
<TabControl.ItemTemplate>
<DataTemplate>
<TextBlock
Text="{Binding Header}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<Controls:MetroContentControl
Content="{Binding Content}" />
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>
これは動作します。デザイナーはすべてのタブ&の内容を表示します。 どのように私はWindowCommandsをバインドできますか?
<Controls:MetroWindow.LeftWindowCommands>
<Controls:WindowCommands ItemsSource="{Binding LeftWindowCommands}">
</Controls:WindowCommands>
</Controls:MetroWindow.LeftWindowCommands>
はさらに私は私のMainViewModelに複数のボタンを追加できるようにしたい: は、私のような何かをしたいです。何かのように:理想的
private MahApps.Metro.Controls.WindowCommands LeftWindowCommandsGiveaway()
{
MahApps.Metro.Controls.WindowCommands command = new MahApps.Metro.Controls.WindowCommands();
command.Items.Add(
new Button { Content = "MyButton #1", Foreground = Brushes.Red });
command.Items.Add(
new Button { Content = "MyButton #2", Foreground = Brushes.Red });
return command;
}
SubMenuには、タブのコマンドが含まれている選択したタブのプロパティにバインドされた 'ItemsControl'がありますか?そのようにして、選択したタブが変わるたびに、SubMenuはそれらのコマンドでいっぱいになります。 –