[WPF]DockPanel

Introduction

DockPanel容器主要為容器內部的控制項提供停靠的機制。

命名空間

System.Windows.Controls

XMLNS

http://schemas.microsoft.com/winfx/xaml/presentation

Assemble

PresentationFramework (在 PresentationFramework.dll)

功能

定義一個區域,讓子項目可以依彼此相對的水平或垂直位置來排列。

範例

<Window x:Class=”Window1”

<pre>    <span class="attr">xmlns</span><span class="kwrd">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span></pre>

<pre class="alt">    <span class="attr">xmlns:x</span><span class="kwrd">="http://schemas.microsoft.com/winfx/2006/xaml"</span></pre>

<pre>    <span class="attr">Title</span><span class="kwrd">="Window1"</span> <span class="attr">Height</span><span class="kwrd">="300"</span> <span class="attr">Width</span><span class="kwrd">="300"</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">    <span class="kwrd">&lt;</span><span class="html">DockPanel</span> <span class="attr">Height</span><span class="kwrd">="263"</span> <span class="attr">Name</span><span class="kwrd">="DockPanel1"</span> <span class="attr">Width</span><span class="kwrd">="276"</span><span class="kwrd">&gt;</span></pre>

<pre>        <span class="kwrd">&lt;</span><span class="html">Menu</span> <span class="attr">DockPanel</span>.<span class="attr">Dock</span><span class="kwrd">="Top"</span> <span class="kwrd">&gt;</span></pre>

<pre class="alt">            <span class="kwrd">&lt;</span><span class="html">MenuItem</span> <span class="attr">Header</span><span class="kwrd">="File"</span><span class="kwrd">&gt;</span></pre>

<pre>                <span class="kwrd">&lt;</span><span class="html">MenuItem</span> <span class="attr">Header</span><span class="kwrd">="Open"</span><span class="kwrd">&gt;&lt;/</span><span class="html">MenuItem</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">            <span class="kwrd">&lt;/</span><span class="html">MenuItem</span><span class="kwrd">&gt;</span></pre>

<pre>        <span class="kwrd">&lt;/</span><span class="html">Menu</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">        </pre>

<pre>        <span class="kwrd">&lt;</span><span class="html">ToolBarPanel</span> <span class="attr">DockPanel</span>.<span class="attr">Dock</span><span class="kwrd">="Top"</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">            <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">HorizontalAlignment</span><span class="kwrd">="Left"</span> <span class="kwrd">&gt;</span>Tool<span class="kwrd">&lt;/</span><span class="html">Button</span><span class="kwrd">&gt;</span></pre>

<pre>        <span class="kwrd">&lt;/</span><span class="html">ToolBarPanel</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">        </pre>

<pre>        <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">Width</span><span class="kwrd">="150"</span> <span class="attr">Background</span><span class="kwrd">="Yellow"</span>   <span class="attr">DockPanel</span>.<span class="attr">Dock</span><span class="kwrd">="Left"</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">            <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Background</span><span class="kwrd">="Gray"</span><span class="kwrd">&gt;</span>Tool1<span class="kwrd">&lt;/</span><span class="html">TextBlock</span><span class="kwrd">&gt;</span></pre>

<pre>            <span class="kwrd">&lt;</span><span class="html">TextBlock</span> <span class="attr">Background</span><span class="kwrd">="Aqua"</span><span class="kwrd">&gt;</span>Tool2<span class="kwrd">&lt;/</span><span class="html">TextBlock</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span></pre>

<pre>        </pre>

<pre class="alt">        <span class="kwrd">&lt;</span><span class="html">StackPanel</span> <span class="attr">Width</span><span class="kwrd">="150"</span> <span class="attr">DockPanel</span>.<span class="attr">Dock</span><span class="kwrd">="Left"</span><span class="kwrd">&gt;</span></pre>

<pre>        <span class="kwrd">&lt;/</span><span class="html">StackPanel</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">        </pre>

<pre>    <span class="kwrd">&lt;/</span><span class="html">DockPanel</span><span class="kwrd">&gt;</span></pre>

<pre class="alt"><span class="kwrd">&lt;/</span><span class="html">Window</span><span class="kwrd">&gt;</span></pre>


執行結果

image