Lorenzo Sciuto
Lorenzo Sciuto

Reputation: 1685

c# wpf layout reusability

I'm trying to make a window layout usable from different windows. enter image description here

As you can see from image, I've got a logo, a left vertical progress bar and two control buttons in the bottom part of the window (plus menu bar and status bar).

Those parts should be always the same in different windows, and play/stop should be interacting run-time with the common parts but also with parts build in the middle of the window ("part in each window different").

I can't understand what i should use for creating a standard layout callable from each window where I need it, made in a way were I can replace for each of those windows just the middle part.

Any tips? I probably just need to understand the way to go (sad to be c# wpf newbie)!

Upvotes: 1

Views: 207

Answers (2)

pete the pagan-gerbil
pete the pagan-gerbil

Reputation: 3166

If you create a user control with a <ContentPresenter> where you want the variable content to be, you can inject your own controls into the user control.

The user control would look like:

<UserControl>
  <Grid>
    <!-- Header Stuff -->

    <ContentPresenter Name="MyContentPresenter" />

    <!-- Footer Stuff -->
  </Grid>
</UserControl>

In your windows, you'd have:

<Window>
  <Grid>
    <MyUserControl>
      <MyUserControl.Content>
        <!-- your window specific code here -->
      </MyUserControl.Content>
    </MyUserControl>
  </Grid>
</Window>

You will need to expose a property called Content on your user control that returns/sets the Content property of the ContentPresenter element on the user control.

In the code-behind of the user control:

public object Content
{ 
  get { return MyContentPresenter.Content; } 
  set { MyContentPresenter.Content = value; } 
}

Upvotes: 0

Chris Woolum
Chris Woolum

Reputation: 2914

You can use a content control and then just switch the content

Master page for regions

This link has what you need. You can put the page templates in a separate file if you will be doing lots of content switching

Upvotes: 3

Related Questions