Grid是以表格形式組織控件的一種佈局方式;
WPF中的Grid的每一個單元格中可以放置一個或多個控件;
WPF中的Grid支持單元格的合併;
Grid中的行和列可以自定義高度(Height)和寬度(Width);
定義Grid包含3行3列,並放置控件;
定義Grid包含3行3列,並放置9個控件;
定義Grid包含2行2列,並放置控件;
佈局時,每個標籤都有開始和結束標籤; <></>;
如果某個標籤被包含在另一個標籤裏,那麼此組件在佈局上就被放在包含它的組件裏面;
現在要把Button放在Grid裏,<Button></Button>要放在<Grid></Grid>內部;
<Grid.RowDefinitions>定義此Grid包含幾行;<Grid.ColumnDefinitions>定義此Grid包含幾列;
放置的控件使用 Grid.Row 和 Grid.Column 屬性指定放置在Grid的某行某列;
這兩句是WPF命名空間,一般都要有;
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
也可以指定一個控件佔據多行或多列;使用 Grid.RowSpan 和 Grid.ColumnSpan屬性;
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<Grid>
<Grid.RowDefinitions>
<!--定義行集合 2行-->
<RowDefinition/>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<!--定義列集合 2列-->
<ColumnDefinition/>
<ColumnDefinition/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Button Content="按鈕1" Grid.Row="0" Grid.Column="0"></Button>
<Button Grid.Row="0" Grid.Column="1"></Button>
<Button Content="佔用一行兩列的按鈕" Grid.Row="1" Grid.RowSpan="1" Grid.ColumnSpan="2"></Button>
</Grid>
</Page>
在kaxaml中編輯好佈局,再把佈局代碼拷貝到VS中加入工程,這工具一般是這麼用的;