locked
what is the best way to switch panel for different content? RRS feed

  • Question

  • i am a novice here. i am making an WPF application with a left hand side panel which displays menu buttons for different operation.

    on my right hand side panel, it is to display the content for the operation chosen by left hand side menu button.

    so you see, my right hand side panel needs to switch from 1 content to another content (or panel). what is the best way / design for this type of behavior.

    any URL or example will be great.

    thanks

    jessi


    1 + 1 = 3
    Friday, November 12, 2010 10:39 AM

Answers

  • Hi,

    That is fine.

    You can have the right hand side as a grid or stackpanel or ContentPresenter and add the usercontrol to that.

    If it is a ItemsControl you are using then make sure you remove the previous element before adding the new one.

     

     


    Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem
    • Proposed as answer by Sheldon _Xiao Thursday, November 18, 2010 1:38 AM
    • Marked as answer by Sheldon _Xiao Friday, November 19, 2010 3:21 AM
    Friday, November 12, 2010 11:38 AM
  • Like Rahul said, if the menu buttons each has a one to one relationship with the content they should show, use the TabControl. This can be customized to fit your look. This is a good starting point -> http://www.c-sharpcorner.com/uploadfile/prathore/tabcontrol01292009003152am/tabcontrol.aspx

     

    If you want a simpler solution than Templating and styling (if you haven't done that before) you could also just Create a simple layout like this

     

     

    <DockPanel>
     <StackPanel>
     <Button Content="Menubutton1"></Button>
     <Button Content="Menubutton2"></Button>
     <Button Content="Menubutton3"></Button>
     </StackPanel>
     <DockPanel Name="ContentPanel">
     <TextBlock Text="UserControls can be put here dynamically from code"/>
     </DockPanel>
    </DockPanel>
    

     

    And then from the button events or any other control you put in the left panel could be used from codebehind to load UserControls of your choice into ContentPanel

     

    Good luck!

    • Proposed as answer by Sheldon _Xiao Thursday, November 18, 2010 1:38 AM
    • Marked as answer by Sheldon _Xiao Friday, November 19, 2010 3:21 AM
    Friday, November 12, 2010 11:39 AM

All replies

  • Hi,

    You can opt for a tab based approach if u need to keep multiple contents open at the same time.

    Each of the content can be created as a different usercontrol and loaded into the content area of the control used in the right panel based on the selection in the left hand side menu.

     

    Feel free to ask if you need any clarification

     


    Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem
    Friday, November 12, 2010 11:26 AM
  • no, i will only show 1 content (or usercontrol) at a time.

    please help.

    jessi


    1 + 1 = 3
    Friday, November 12, 2010 11:31 AM
  • Hi,

    That is fine.

    You can have the right hand side as a grid or stackpanel or ContentPresenter and add the usercontrol to that.

    If it is a ItemsControl you are using then make sure you remove the previous element before adding the new one.

     

     


    Please mark posts as answers/helpful if it answers your query. This would be helpful for others facing the same kind of problem
    • Proposed as answer by Sheldon _Xiao Thursday, November 18, 2010 1:38 AM
    • Marked as answer by Sheldon _Xiao Friday, November 19, 2010 3:21 AM
    Friday, November 12, 2010 11:38 AM
  • Like Rahul said, if the menu buttons each has a one to one relationship with the content they should show, use the TabControl. This can be customized to fit your look. This is a good starting point -> http://www.c-sharpcorner.com/uploadfile/prathore/tabcontrol01292009003152am/tabcontrol.aspx

     

    If you want a simpler solution than Templating and styling (if you haven't done that before) you could also just Create a simple layout like this

     

     

    <DockPanel>
     <StackPanel>
     <Button Content="Menubutton1"></Button>
     <Button Content="Menubutton2"></Button>
     <Button Content="Menubutton3"></Button>
     </StackPanel>
     <DockPanel Name="ContentPanel">
     <TextBlock Text="UserControls can be put here dynamically from code"/>
     </DockPanel>
    </DockPanel>
    

     

    And then from the button events or any other control you put in the left panel could be used from codebehind to load UserControls of your choice into ContentPanel

     

    Good luck!

    • Proposed as answer by Sheldon _Xiao Thursday, November 18, 2010 1:38 AM
    • Marked as answer by Sheldon _Xiao Friday, November 19, 2010 3:21 AM
    Friday, November 12, 2010 11:39 AM
  • Hi All,

    Sorry for my jumping.

    Hi jessi

    I am marking your issue as "Answered", if you still have anyting is unclear, please ummark.

     

    Best regards,

    Sheldon _Xiao


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework!
    Friday, November 19, 2010 3:21 AM