Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WPF
  4. Change content in MainWindow / Navigation

Change content in MainWindow / Navigation

Scheduled Pinned Locked Moved WPF
wpfcsharpcsshelptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    PingOfDeath1983
    wrote on last edited by
    #1

    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

    A 1 Reply Last reply
    0
    • P PingOfDeath1983

      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

      A Offline
      A Offline
      AspDotNetDev
      wrote on last edited by
      #2

      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.

      [Forum Guidelines]

      B 1 Reply Last reply
      0
      • A AspDotNetDev

        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.

        [Forum Guidelines]

        B Offline
        B Offline
        BlitzPackage
        wrote on last edited by
        #3

        I would consider using an event handler.

        A 1 Reply Last reply
        0
        • B BlitzPackage

          I would consider using an event handler.

          A Offline
          A Offline
          AspDotNetDev
          wrote on last edited by
          #4

          The OP wanted to avoid ".cs" code (i.e., XAML only).

          [Forum Guidelines]

          Q 1 Reply Last reply
          0
          • A AspDotNetDev

            The OP wanted to avoid ".cs" code (i.e., XAML only).

            [Forum Guidelines]

            Q Offline
            Q Offline
            quetzilla
            wrote on last edited by
            #5

            There's no way to do it in XAML only without using a markup extension library. This seems like a basic M-V-whatever issue.

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups