それでは本題です。3 つのパネルに分割されたウィンドウがあります。中央には描画面が含まれ、左側にはタブ コントロールが含まれています。タブ コントロールのタブは、右側のパネルに新しいメニューを開く必要があるボタンのリストで構成されています。コードでこれを行う方法がわからないので、実行時に C# で各ボタンを個別に作成することにしました。それについてもっと良い方法が必要なようです。現在、ボタン クリック イベントに対して以下の関数を呼び出して、実行時に「tabctrl」という名前の TabControl の右側のパネルにさまざまなメニューを描画します。描画するメニューのセットを指定するには文字列引数が必要ですが、この時点ではメニューの 1 つのコードしか記述していません。以下は、関数と xml のコードです。これについてもっと良い方法はありますか?
xml:
<TabControl DockPanel.Dock="Right" Background="White" x:Name="tabctrl">
<TabItem Height ="38" Name="Tab1" Header="tab3"/>
</TabControl>
c#:
private void menuOpen(string menuSelected)
{
//Logic statement for what menu is being opened
switch (menuSelected)
{
case "BackGround":
{
//Remove Current Tabs
//Initialize Tab Item, set title, and add tab item to tab control
TabItem BackGround = new TabItem();
BackGround.Header = "BackGround";
tabctrl.Items.Insert(1, BackGround);
BackGround.Height = 38;
//Initialize Stack Panel, set orientation, and add to tab control
StackPanel panel = new StackPanel();
panel.Orientation = Orientation.Vertical;
BackGround.Content = panel;
//Initialize Menu Items
Button AddMap = new Button();
Button AddDemoMap = new Button();
Button RemoveMap = new Button();
Button MoveSelected = new Button();
Button Properties = new Button();
Button ScaleBackground = new Button();
//Define Button Text
AddMap.Content = "Add Map";
AddDemoMap.Content = "Add Demo Map";
RemoveMap.Content = "Remove Map";
MoveSelected.Content = "Move Selected Map to Top of List";
Properties.Content = "Properties";
ScaleBackground.Content = "Scale Background to Pipes";
AddMap.Height = 50;
AddDemoMap.Height = 50;
RemoveMap.Height = 50;
MoveSelected.Height = 50;
Properties.Height = 50;
ScaleBackground.Height = 50;
//Add Buttons to StackPanel
panel.Children.Add(AddMap);
panel.Children.Add(AddDemoMap);
panel.Children.Add(RemoveMap);
panel.Children.Add(MoveSelected);
panel.Children.Add(Properties);
panel.Children.Add(ScaleBackground);
}
break;