Change content in MainWindow / Navigation
-
Hi, I cant figure out how to switch my customcontrols when clicking on a menubar-button. I have a MainWindow containing the following XAML:
<DockPanel x:Name="MainWindow">
<Menu Name="dropDownMenu" DockPanel.Dock="Top"> <MenuItem Name="dropDownPage1" Header="File"> <MenuItem Header="Page1" Click="dropDown\_Page1"/> </MenuItem> <MenuItem Name="dropDownPage2" Header="File"> <MenuItem Header="Page2" Click="dropDown\_Page2"/> </MenuItem> </Menu> <Grid Name="gridMainContent" DockPanel.Dock="Top"> <TextBlock>placeholder main content</TextBlock> </Grid> <Grid Name="gridStatusBar" DockPanel.Dock="Bottom"> <TextBlock>placeholder statusbar</TextBlock> </Grid> </DockPanel>
The task is when clicking on one menubutton i.e. "dropDown_Page1", changing the content of the grid "gridMainContent". Is there a way to place customcontrols into a grid without code in any *.cs File ? It would be wonderfull if somebody could help me on this. Cause I´m new to WPF, I welcome you to show me other ways of doing this! Thx! PingOfDeath
-
Hi, I cant figure out how to switch my customcontrols when clicking on a menubar-button. I have a MainWindow containing the following XAML:
<DockPanel x:Name="MainWindow">
<Menu Name="dropDownMenu" DockPanel.Dock="Top"> <MenuItem Name="dropDownPage1" Header="File"> <MenuItem Header="Page1" Click="dropDown\_Page1"/> </MenuItem> <MenuItem Name="dropDownPage2" Header="File"> <MenuItem Header="Page2" Click="dropDown\_Page2"/> </MenuItem> </Menu> <Grid Name="gridMainContent" DockPanel.Dock="Top"> <TextBlock>placeholder main content</TextBlock> </Grid> <Grid Name="gridStatusBar" DockPanel.Dock="Bottom"> <TextBlock>placeholder statusbar</TextBlock> </Grid> </DockPanel>
The task is when clicking on one menubutton i.e. "dropDown_Page1", changing the content of the grid "gridMainContent". Is there a way to place customcontrols into a grid without code in any *.cs File ? It would be wonderfull if somebody could help me on this. Cause I´m new to WPF, I welcome you to show me other ways of doing this! Thx! PingOfDeath
Include a namespace reference to the assembly containing your custom control, then use your custom control in the XAML. Read up on custom controls and user controls if you don't know what the previous sentence means. You can initially hide it, and then display it when the menu item is selected. Might require some code to handle the command, but you might be able to just accomplish it with an event trigger.
-
Include a namespace reference to the assembly containing your custom control, then use your custom control in the XAML. Read up on custom controls and user controls if you don't know what the previous sentence means. You can initially hide it, and then display it when the menu item is selected. Might require some code to handle the command, but you might be able to just accomplish it with an event trigger.
I would consider using an event handler.
-
I would consider using an event handler.
The OP wanted to avoid ".cs" code (i.e., XAML only).
-
The OP wanted to avoid ".cs" code (i.e., XAML only).