Dockpanel-the most regular layout Control

Source: Internet
Author: User

Dockpanel-the most regular layout Control

Such a dockpanel:

    <DockPanel LastChildFill="True">        <TextBlock  Text="1.Dock.Top" DockPanel.Dock="Top" Background="Bisque" Margin="0" Height="50"  VerticalAlignment="Top"/>        <TextBlock  Text="2.Dock.Bottom" DockPanel.Dock="Bottom" Background="GreenYellow"   Margin="0" Height="20" VerticalAlignment="Bottom"/>        <TextBlock  Text="3.Dock.Left" DockPanel.Dock="Left" Background="Tan"  Width="100"  />        <Grid DockPanel.Dock="Right" x:Name="gridRight"  Width="200">            <TextBlock  Text="4.Dock.Right" Background="Honeydew"    HorizontalAlignment="Stretch"/>        </Grid>        <TextBlock  Text="last" Background="Aquamarine" />    </DockPanel>

 

Each element]
This edge is very good. The guy in the middle can take advantage of the blessing of the parent element lastchildfill = "true" and exclusively occupy the remaining area.

Observe the rules because of two points:

  1. The element is docked to only one side, and the last element fills the blank area.
  2. Strictly follow the first-in-first-out principle, especially the [controversial regions]

Use the first point to indent the space on the edge so that the middle area occupies a large amount of space.

        <Grid DockPanel.Dock="Right" x:Name="gridRight"  Width="200">            <TextBlock  Text="4.Dock.Right" Background="Honeydew"    HorizontalAlignment="Stretch"/>            <ToggleButton Content="->" Height="23" HorizontalAlignment="Left" Margin="0,50,0,0"  Name="btnRight" VerticalAlignment="Top" Width="23"  >                <ToggleButton.Triggers>                    <EventTrigger   RoutedEvent="ToggleButton.Checked">                        <StopStoryboard BeginStoryboardName="collapsed" />                        <BeginStoryboard x:Name="expand"   HandoffBehavior="SnapshotAndReplace">                            <Storyboard  >                                <DoubleAnimation      Duration="00:00:0.10 "  Storyboard.TargetName="gridRight" Storyboard.TargetProperty="Width" To="50" />                                <ObjectAnimationUsingKeyFrames      Storyboard.TargetProperty="Content"   >                                    <DiscreteObjectKeyFrame Value="->"  KeyTime="00:00:0.10" />                                </ObjectAnimationUsingKeyFrames>                            </Storyboard>                        </BeginStoryboard>                    </EventTrigger>                    <EventTrigger RoutedEvent="ToggleButton.Unchecked">                        <StopStoryboard BeginStoryboardName="expand" />                        <BeginStoryboard x:Name="collapsed"   HandoffBehavior="SnapshotAndReplace">                            <Storyboard  >                                <DoubleAnimation       Duration="00:00:0.10 "    Storyboard.TargetName="gridRight" Storyboard.TargetProperty="Width" To="200" />                                <ObjectAnimationUsingKeyFrames      Storyboard.TargetProperty="Content"   >                                    <DiscreteObjectKeyFrame Value="<-"  KeyTime="00:00:0.10" />                                </ObjectAnimationUsingKeyFrames>                            </Storyboard>                        </BeginStoryboard>                    </EventTrigger>                </ToggleButton.Triggers>            </ToggleButton>        </Grid>

The second point can be used to change the layout as needed.

For example
There is a cross area. If you want to divide this area to the left, place the element on the left before the element on the lower side, as shown below:

<TextBlock  Text="3.Dock.Left" DockPanel.Dock="Left" Background="Tan"  Width="100"  /><TextBlock  Text="2.Dock.Bottom" DockPanel.Dock="Bottom" Background="GreenYellow"   Margin="0" Height="20" VerticalAlignment="Bottom"/>

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.