Same header & footer in all WPF windows

后端 未结 4 1873
终归单人心
终归单人心 2021-01-14 07:48

In my project I have same header & footer for all windows (I have more then 20 wpf windows in this project), Only Content has changed. This is WPF project. If its a asp.

4条回答
  •  感情败类
    2021-01-14 08:10

    I'm not a 100% sure what do you mean by "all windows", but a good approach would be to have a header and a footer UserControls.

    You can set them whichever way you want, (text, colors, etc), and then, in all your windows you could have a grid with 3 elements, stackpanel, dockpanel, whatever you want, which will have the header, then your content, and last, your footer.


    Edit: As per comment: Instead of having this:

    
        
            
            
            
        
    
    

    You can have a UserControls (lets say called HeaderControl), and then all you need to do is

    1. Add the namespace so you can use it.
    2. Add it like you'll add any other control.
    3. Enjoy reusability.

    steps explanation:

    1. Add this to your windown with the rest of the xmlns.... definitions:
      xmlns:controls="clr-namespace:WpfApplication1"

    2. Changing the first control from label to our resource:
      Instead of write:

    example

提交回复
热议问题