So here's the issue. I have a window divided into three panels. The middle contains a drawing surface and the left contains a tab control. The tab control's tab eats each consist of a list of buttons that must open new menu's in the right panel. I can't figure out how to do this in code so I resorted to individually creating each button at run time in C#. Seems like there has to be a better way to go about it. I currently call the below function for button click events to draw different menu's in the TabControl named "tabctrl" right panel at runtime. It takes a string argument to specify what set of menus to draw, although at this point I've only written the code for one the menu's. Below is the code for the function and the xml. Is there a better way to go about this?
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;