Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College



The DockPanel compared to the StackPanel and the WrapPanel can be used to design more complex layouts, and as a root element replaced the DataGrid. With the help of DockPanel.Dock’s features, the location of each child elements can be set inside the DockPanel.

IV.5. DockPanel.Dock

Create the two applications shown below to understand the DockPanel.

Example IV.5 DockPanel

IV.6. DockPanel

<DockPanel LastChildFill="True">

     <Button Content="Dock=Top" DockPanel.Dock="Top" Background="Beige"/>

     <Button Content="Dock=Right" DockPanel.Dock="Right" Background="Gold"/>

     <Button Content="Dock=Left" Background="Gold"/>

     <Button Content="Dock=Bottom" DockPanel.Dock="Bottom" Background="Beige"/>

     <Image Source="Nap.gif" Stretch="Fill"/>


LastChildFill (True or False) property specifies that the last element fills or not the available space.

Example IV.6 Saturn - DockPanel


IV.7. DockPanel

    <Window x:Class="Bolygok.MainWindow"



        Title="Saturn" Height="400" Width="600" Background="Yellow">

        <DockPanel LastChildFill="True">

            <Border DockPanel.Dock="Top" Height="80"

                 CornerRadius="10" Margin="10">

                <TextBlock HorizontalAlignment="Center"

                       VerticalAlignment="Center" FontSize="36"

                       FontFamily="Book Antiqua" Foreground="White">




                    <ImageBrush ImageSource="/Planets;component/Images/Galaxy1.jpg"/>



            <Border DockPanel.Dock="Bottom">


            <Border Height="50"  Background="Black" BorderBrush="Black" BorderThickness="1" DockPanel.Dock="Bottom">

                <StackPanel Orientation="Horizontal">

                    <TextBlock Foreground="White" Width="580" TextWrapping="Wrap" Text="

Saturn is the sixth planet from the Sun and the second largest planet in the Solar System, after Jupiter. Named after the Roman god of agriculture, Saturn, its astronomical symbol (♄) represents the god's sickle. Saturn is a gas giant with an average radius about nine times that of Earth.” />




            <Border Background="Black" CornerRadius="10" Margin="10" Padding="10"            DockPanel.Dock="Left">

                <StackPanel Background="Black">

                    <TextBlock Text="Data" Foreground="White" HorizontalAlignment="Center"                     FontSize="16" />


                    <TextBlock Text="Mass" Foreground="White"/>

                    <TextBlock Text="95,184 (earthmass)" Foreground="White"/>


                    <TextBlock Text="Semi-major axis" Foreground="White"/>

                    <TextBlock Text="1427,0 million km" Foreground="White"/>


                    <TextBlock Text="Orbital period" Foreground="White"/>

                    <TextBlock Text="10759,2 days" Foreground="White"/>


                    <TextBlock Text="Orbital velocity" Foreground="White"/>

                    <TextBlock Text="9,64 km/s" Foreground="White"/>



            <Border Background="Black" BorderBrush="Black" BorderThickness="1"             CornerRadius="10" Margin="10">

               <Image Source="/Bolygok;component/Images/Szaturnusz.jpg" />