9

I know a only little about dock panel, following is the code is used:

<DockPanel LastChildFill="True" >
    <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" VerticalAlignment="Center" Margin="10" >
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Left" VerticalAlignment="Center" >
            <TextBlock Height="24" Name="Welcome" Text="Welcome" FontSize="14" />
        </StackPanel>
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Right" VerticalAlignment="Center" >
            <TextBlock Height="24" Name="Welcomee" Text="Welcomee" FontSize="14" />
        </StackPanel>
    </StackPanel>
</DockPanel>

The result is like this:

WelcomeWelcomee

However, the code must result in something like this:

Welcome                                                              Welcomee

So could you please tell me where I misunderstood the concept.

Achilles
  • 1,554
  • 1
  • 28
  • 36
surpavan
  • 1,372
  • 7
  • 34
  • 66

1 Answers1

7

Your first StackPanel should not contain the other two stack panels. It contains the other two. DockPanel.Dock="left" only applies to the immediate children of the DockPanel.

   <DockPanel>
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" VerticalAlignment="Center" Margin="10" >Top
        </StackPanel>
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Left" VerticalAlignment="Center" >
                <TextBlock Height="24" Name="Welcome" Text="Welcome" FontSize="14" />
        </StackPanel>
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Right" VerticalAlignment="Center" >
               <TextBlock Height="24" Name="Welcomee" Text="Welcomee" FontSize="14" />
        </StackPanel>
    </DockPanel>
agent-j
  • 27,335
  • 5
  • 52
  • 79
  • Working and thanks for the explanation on concept. I would remember that Dockpanel only effects its immediate controls. Thank you. – surpavan Jul 01 '11 at 16:55
  • @agent-j this ain't working for me, could you take a look at my question: http://stackoverflow.com/questions/39766035/wpf-dock-panel-dock-left-and-dock-right/39767074?noredirect=1#comment66830119_39767074 – Roxy'Pro Sep 29 '16 at 12:36