Ugrás a tartalomhoz

.NET Programming Technologies

Gergely Kovásznai, Csaba Biró

Eszterházy Károly College

DockPanel

DockPanel

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"/>

</DockPanel>

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"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        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">

                Saturn

                </TextBlock>

                <Border.Background>

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

                </Border.Background>

            </Border>

            <Border DockPanel.Dock="Bottom">

            </Border>

            <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.” />

                    </TextBlock>

                </StackPanel>

            </Border>

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

                <StackPanel Background="Black">

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

                    <Separator/>

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

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

                    <Separator/>

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

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

                    <Separator/>

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

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

                    <Separator/>

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

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

                </StackPanel>

            </Border>

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

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

            </Border>

        </DockPanel>

    </Window>