直接貼代碼了:
XAML:
<Window x:Class="HelloWorld.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800" Loaded="Window_Loaded"> <Window.Resources> <!-- 下面是設置讓所有的 Button 控件的默認樣式 --> <Style TargetType="{x:Type Button}"> <Setter Property="Margin" Value="5"></Setter> <Setter Property="Padding" Value="5"></Setter> <!--<Setter Property="HorizontalAlignment" Value="Center" /> <Setter Property="VerticalAlignment" Value="Center" />--> </Style> </Window.Resources> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"/><!-- 實際高度 --> <RowDefinition Height="*"/><!-- 剩余高度 --> <RowDefinition Height="Auto"/><!-- 實際高度 --> </Grid.RowDefinitions> <Label Grid.Row="0" x:Name="label1" Content="Hello World " HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="20" DockPanel.Dock="Top"/> <Grid Grid.Row="2"> <Grid.RowDefinitions> <RowDefinition Height="Auto" /><!-- 實際高度 --> <RowDefinition Height="Auto" /><!-- 實際高度 --> <RowDefinition Height="*" /><!-- 剩余高度 --> </Grid.RowDefinitions> <Button Grid.Row="0" Name="Button1" DockPanel.Dock="Top" Height="Auto" Content="Button1" /> <Button Grid.Row="1" Name="Button2" DockPanel.Dock="Top" Height="Auto" Content="Button2" /> <ListBox x:Name="ListBoxLog" Grid.Row="2" SelectionMode="Single"/> </Grid> <Button Grid.Row="3" DockPanel.Dock="Bottom" Content="Exit" FontSize="20" /> </Grid> </Window>
效果圖:
謝謝瀏覽!