Bish25
Bish25

Reputation: 616

Having Trouble With WPF Layout with user controls

I'm currently trying to get three user controls to work together, in place i have a dock panel which I am adding too. However I cant get the layout perfect, I would prefer to not add user control 1 within user control 2.

Example of layout

Edit: Imagine that the image is spelt Achieve and not Acheive.

Upvotes: 0

Views: 83

Answers (2)

tgpdyk
tgpdyk

Reputation: 1233

No, you cannot do that in DockPanel without the ugly margin manipulation. 1 and 2 should be in a Canvas:

 <Canvas x:Name="canvas">
        <Grid>
            <!-- usercontrol 1--> 
            <TextBlock Text="1"
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"/>
        </Grid>
        <DockPanel Background="Transparent"
                    Height="{Binding ActualHeight, ElementName=canvas}" 
                    Width="{Binding ActualWidth, ElementName=canvas}">
             <!-- usercontrol 2-->  
            <TextBlock Text="2" 
                       HorizontalAlignment="Center"
                       VerticalAlignment="Center"/>
        </DockPanel>
 </Canvas>

Upvotes: 1

Kamil Solecki
Kamil Solecki

Reputation: 1117

If you want Control 1 to be above Control 2 and not be contained in it, put them in a grid and give Control 1 a higher ZIndex:

<Grid>
    <Control1 Grid.ZIndex="2" />
    <Control2 Grid.ZIndex="1" />
    <Control3 Grid.ZIndex="1" />
</Grid>

Here is the MSDN for reference.

Upvotes: 1

Related Questions