DockPanel

 

DockPanel是一个停靠的模板。在下面的例子中,主要是有一个myDP.LastChildFill属性问题,这个属性自定义状态下是True,rect2就是自动充满余下的部分,当为False时,rect2为定义的最小值。

还有DockPanel.SetDock(rect1, Dock.Top)是设置rect1在myDP这个DockPanel下的停靠位置。

XAML代码:
<Page

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

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

       x:Class="Controls.DockPaneltest"

       x:Name="Page"

       WindowTitle="Page"

       FlowDirection="LeftToRight"

       Width="640" Height="480"

       WindowWidth="640" WindowHeight="480">

<DockPanel Background="White">

    <TextBlock FontSize="16" FontWeight="Bold" DockPanel.Dock="Top" Margin="0,0,0,10">Dock Property Sample</TextBlock>

    <TextBlock DockPanel.Dock="Top" Margin="0,0,0,10" TextWrapping="Wrap">

      Click the buttons below to manipulate the associated Dock properties

      of the rectangle elements below. This example is designed to help the user understand layout behavior in

      a DockPanel element.

    </TextBlock>

    <TextBlock DockPanel.Dock="Top" Name="Txt1">The Dock property of the LightCoral Rectangle is set to Left</TextBlock>

    <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="0,0,0,10">

      <Button Click="OnClick1" Background="LightCoral">Dock = "Left"</Button>

      <Button Click="OnClick2" Background="LightCoral">Dock = "Right"</Button>

      <Button Click="OnClick3" Background="LightCoral">Dock = "Top"</Button>

      <Button Click="OnClick4" Background="LightCoral">Dock = "Bottom"</Button>

    </StackPanel>

 

    <TextBlock DockPanel.Dock="Top" Name="Txt2">The Dock property of the LightSkyBlue Rectangle is set to Right</TextBlock>

 

    <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="0,0,0,10">

      <Button Click="OnClick5" Background="LightSkyBlue" Foreground="White">Dock = "Left"</Button>

      <Button Click="OnClick6" Background="LightSkyBlue" Foreground="White">Dock = "Right"</Button>

      <Button Click="OnClick7" Background="LightSkyBlue" Foreground="White">Dock = "Top"</Button>

      <Button Click="OnClick8" Background="LightSkyBlue" Foreground="White">Dock = "Bottom"</Button>

    </StackPanel>

 

    <TextBlock DockPanel.Dock="Top" Name="Txt3">The LastChildFill property is set to True (default).</TextBlock>

    <StackPanel Orientation="Horizontal" DockPanel.Dock="Top" Margin="0,0,0,10">

      <Button Click="OnClick9" Background="White">LastChildDock="True"</Button>

      <Button Click="OnClick10" Background="White">LastChildDock="False"</Button>

    </StackPanel>

 

    <Border Background="LightGoldenRodYellow" BorderBrush="Black" BorderThickness="1">

      <DockPanel Name="myDP">

        <Rectangle Name="rect1" MinWidth="200" MinHeight="200" Stroke="Black" Fill="LightCoral" />

        <Rectangle Name="rect2" MinWidth="200" MinHeight="200" Stroke="Black" Fill="LightSkyBlue" />

      </DockPanel>

    </Border>

 </DockPanel>

</Page>

 CS代码:

public void OnClick1(object sender, RoutedEventArgs e)

        {

            DockPanel.SetDock(rect1, Dock.Left);

            Txt1.Text = "The Dock Property of the LightCoral Rectangle is set to Left";

        }

 

        public void OnClick2(object sender, RoutedEventArgs e)

        {

            DockPanel.SetDock(rect1, Dock.Right);

            Txt1.Text = "The Dock Property of the LightCoral Rectangle is set to Right";

        }

 

        public void OnClick3(object sender, RoutedEventArgs e)

        {

            DockPanel.SetDock(rect1, Dock.Top);

            Txt1.Text = "The Dock Property of the LightCoral Rectangle is set to Top";

        }

 

        public void OnClick4(object sender, RoutedEventArgs e)

        {

            DockPanel.SetDock(rect1, Dock.Bottom);

            Txt1.Text = "The Dock Property of the LightCoral Rectangle is set to Bottom";

        }

 

        public void OnClick5(object sender, RoutedEventArgs e)

        {

            DockPanel.SetDock(rect2, Dock.Left);

            Txt2.Text = "The Dock Property of the LightSkyBlue Rectangle is set to Left";

        }

 

        public void OnClick6(object sender, RoutedEventArgs e)

        {

            DockPanel.SetDock(rect2, Dock.Right);

            Txt2.Text = "The Dock Property of the LightSkyBlue Rectangle is set to Right";

        }

 

        public void OnClick7(object sender, RoutedEventArgs e)

        {

            DockPanel.SetDock(rect2, Dock.Top);

            Txt2.Text = "The Dock Property of the LightSkyBlue Rectangle is set to Top";

        }

 

        public void OnClick8(object sender, RoutedEventArgs e)

        {

            DockPanel.SetDock(rect2, Dock.Bottom);

            Txt2.Text = "The Dock Property of the LightSkyBlue Rectangle is set to Bottom";

        }

 

        public void OnClick9(object sender, RoutedEventArgs e)

        {

            myDP.LastChildFill = true;

            Txt3.Text = "The LastChildFill property is set to True (default)";

        }

 

        public void OnClick10(object sender, RoutedEventArgs e)

        {

            myDP.LastChildFill = false;

            Txt3.Text = "The LastChildFill property is set to True False";

        }
本文参考MSDN组织。

转载于:https://www.cnblogs.com/axzxs2001/archive/2007/03/20/681330.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值