In WPF, I want to create a Window that looks like the following:
Application with user controls http://www.freeimagehosting.net/uploads/86209e1a87.png
On the screen are four user control, #1, 2, 3, 4. As you can see, user control 2 should not be rendered as a box, but inlined.
If this were a WPF flow document:
The reason is that 2 could be used in another form without splitting for 3.
Do you have any idea how to do this in a proper manner ?
Some idea already thought of:
And some others that are not as clean...
Any thoughts ?
Thanks,
Patrick
User controls, in WPF represented by the UserControl class, is the concept of grouping markup and code into a reusable container, so that the same interface, with the same functionality, can be used in several different places and even across several applications.
Your UserControls should NOT have ViewModels designed specifically for them. This is, in fact, a code smell. It doesn't break your application immediately, but it will cause you pain as you work with it. A UserControl is simply an easy way to create a Control using composition.
A window is managed by the OS and is placed on the desktop. A UserControl is managed by wpf and is placed in a Window or in another UserControl. Applcations could be created by have a single Window and displaying lots of UserControls in that Window.
I think you have your form broken up incorrectly, IMO.
Area 2 should not include the bottom piece you're describing that you want to have "inlined".
It should separate (as far as layout is concerned), and probably fit in a grid with 2 columns and 2 rows along with Area 3 and Area 4. Area 3 would then need to have a rowspan of 2.
The XAML, in this case, would actually be pretty clean if done this way.
It might look something like this:
<Grid>
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<uC:Area1 Grid.Row="0"><!-- Area Control here --></uC:Area1>
<uC:Area2 Grid.Row="1"><!-- Area Control here --></uC:Area2>
<Grid Grid.Row="2">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<uC:AreaDuree Grid.Row="0" Grid.Column="0">
<!-- Area Control here -->
</uC:AreaDuree>
<uC:Area4 Grid.Row="1" Grid.Column="0">
<!-- Area Control here -->
</uC:Area4>
<uC:Area3 Grid.RowSpan="2" Grid.Column="1">
<!-- Area Control here -->
</uC:Area3>
</Grid>
</Grid>
I suggest you to split your Control #2 in 3 or 4 more specific UserControl. Then load #2, #3, #4 inside a WrapPanel. Check this link: Layout of UserControl to implement an intelligent wrap panel Arrange and Mesure strategy.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With