[WPF]Grid

Introduction

Grid容器提供像表格一樣可分割列與行的功能 。類似HTML中的Tabel。

命名空間

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">Grid</span><span class="kwrd">&gt;</span></pre>

<pre>        <span class="kwrd">&lt;</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">&gt;</span></pre>

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

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

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

<pre>        <span class="kwrd">&lt;/</span><span class="html">Grid.RowDefinitions</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">        <span class="kwrd">&lt;</span><span class="html">Grid.ColumnDefinitions</span> <span class="kwrd">&gt;</span></pre>

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

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

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

<pre class="alt">        <span class="kwrd">&lt;/</span><span class="html">Grid.ColumnDefinitions</span><span class="kwrd">&gt;</span></pre>

<pre>        <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">FontSize</span><span class="kwrd">="50"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="0"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="0"</span><span class="kwrd">&gt;</span>O<span class="kwrd">&lt;/</span><span class="html">Button</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">        <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">FontSize</span><span class="kwrd">="50"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="0"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">&gt;</span>X<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">Button</span> <span class="attr">FontSize</span><span class="kwrd">="50"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="0"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="2"</span><span class="kwrd">&gt;</span>O<span class="kwrd">&lt;/</span><span class="html">Button</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">        <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">FontSize</span><span class="kwrd">="50"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="1"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="0"</span><span class="kwrd">&gt;</span>O<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">Button</span> <span class="attr">FontSize</span><span class="kwrd">="50"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="1"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">&gt;</span>X<span class="kwrd">&lt;/</span><span class="html">Button</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">        <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">FontSize</span><span class="kwrd">="50"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="1"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="2"</span><span class="kwrd">&gt;</span>X<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">Button</span> <span class="attr">FontSize</span><span class="kwrd">="50"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="2"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="0"</span><span class="kwrd">&gt;</span>X<span class="kwrd">&lt;/</span><span class="html">Button</span><span class="kwrd">&gt;</span></pre>

<pre class="alt">        <span class="kwrd">&lt;</span><span class="html">Button</span> <span class="attr">FontSize</span><span class="kwrd">="50"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="2"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="1"</span><span class="kwrd">&gt;</span>O<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">Button</span> <span class="attr">FontSize</span><span class="kwrd">="50"</span> <span class="attr">Grid</span>.<span class="attr">Row</span><span class="kwrd">="2"</span> <span class="attr">Grid</span>.<span class="attr">Column</span><span class="kwrd">="2"</span><span class="kwrd">&gt;</span>O<span class="kwrd">&lt;/</span><span class="html">Button</span><span class="kwrd">&gt;</span></pre>

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

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


執行結果

image