3

I would like to build a WPF window application using the following layout structure. Consider title and button on left hand frame/window like "Master Pages" in ASP.Net. On the right hand frame it should be a WPF navigation window.

When I include Navigation Window as an UI element at the last stack panel, it throws me and error. How should I design the entire layout according to the image screenshot below? Thanks

<Window x:Class="MainWindow"
     xmlns:local="clr-namespace:ClientSocket"        
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title=" Desktop" Height="841" Width="1271" WindowStartupLocation="CenterScreen" WindowState="Maximized">
    <DockPanel>
        <StackPanel DockPanel.Dock ="Top"  Orientation="Horizontal" Background="Red">
            <TextBlock  Background="red"  FontSize ="36" Width="482" >
           Main Title
            </TextBlock>          
        </StackPanel>
        <StackPanel Background="LightGray" DockPanel.Dock ="Left" Width="145">
            <Button Content="Button1" Name="btnAndroid" Width="119" Margin="3" BorderBrush="{StaticResource {x:Static SystemColors.InfoBrushKey}}" />
            <Button Content="Button2" Name="btnDownloads" Width="119" Margin="3" BorderBrush="{StaticResource {x:Static SystemColors.InfoBrushKey}}" />
            <Button Content="AddNewDownloads" Height="37" Name="Button1" Width="133" />
        </StackPanel>
        <StackPanel>
        <NavigationWindow Height="auto" Width="auto" Name="nwMain" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" BorderBrush="Blue" BorderThickness="1"  />
        </StackPanel>
    </DockPanel>
</Window>

enter image description here

H.B.
  • 166,899
  • 29
  • 327
  • 400
Bih Cheng
  • 655
  • 1
  • 13
  • 28

1 Answers1

4

You cannot add a window as the child of anything, there is a nestable navigation control which you can use here instead, it is called Frame.

Layout-wise i would recommend a Grid with two rows, contains another Grid (in Grid.Row="1") with two columns.

DockPanels are sad controls that probably should not be used, unless someone points a gun at you and tells you to.

H.B.
  • 166,899
  • 29
  • 327
  • 400
  • Hi H.B. I can try remove dockpanel and use grid to layout this structure, but this does not answer the question on how to put navigation window inside another window (refer to xaml code above). I actually don't want to put a navigation window inside another window as its a run time error but seeking a solution that can achieve a layout as per screenshot above – Bih Cheng Nov 24 '11 at 03:12
  • @simeh: Windows cannot be the children of anything, if you have something that needs to be hosted inside another window you should convert it into a `UserControl`. In fact you should just make everything a `UserControl` that way you never run into such issues. – H.B. Nov 24 '11 at 03:14
  • @simeh: In this case you cannot change that, so you should use a `Frame` control instead i think. – H.B. Nov 24 '11 at 03:18
  • In fact i'm currently using frame method before i changed it to NavigationWindow to give it a try. The reason I change is because when I use frame to open another "page", subsequent pages will overlap current page and create multiple layer effect... see screenshot here and notice the thick blue line, it has become multi layered http://imageshack.us/photo/my-images/819/pageserror.png/ – Bih Cheng Nov 24 '11 at 03:29
  • @simeh: How do you open them? You should just navigate from one page to the other, this should not happen. – H.B. Nov 24 '11 at 08:07
  • I've managed to change my code to use Grids layout instead of DockPanels. I also manage to get desired layout with Navigation Window on right panel. However when I'm inside a page opened by Navigation Window, if I want to call main page's frame to open another page, how can I access this object? Thanks – Bih Cheng Nov 24 '11 at 08:19
  • @simeh: I do not know. Have you read the [navigation overview](http://msdn.microsoft.com/en-us/library/ms750478.aspx) and its subpages? – H.B. Nov 24 '11 at 08:22