1. 程式人生 > WINDOWS開發 >WPF 一個佈局的簡單例子

WPF 一個佈局的簡單例子

1. 注意 Grid 裡面,不管是行還是列,預設的尺寸大小就是,"1*"

2. 除了設定 “*”,固定值,還可以設定成 "Auto"

3. 結合圖片的 Stretch 屬性,可以做一些有意思的的效果

<Window x:Class="WpfApp24.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" xmlns:local="clr-namespace:WpfApp24" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800"> <Grid> <Grid.RowDefinitions> <RowDefinition Height="Auto"></
RowDefinition> <RowDefinition Height="*"></RowDefinition> </Grid.RowDefinitions> <Grid Grid.Row="0"> <Grid.ColumnDefinitions> <ColumnDefinition Width="*"></ColumnDefinition> <ColumnDefinition
Width="Auto"></ColumnDefinition> </Grid.ColumnDefinitions> <Image Grid.Row="0" Source="Image1.jpg"></Image> <StackPanel Grid.Column="1" Background="AliceBlue" Width="300"></StackPanel> </Grid> <TextBlock Grid.Row="1"></TextBlock> </Grid> </Window>

效果:

技術分享圖片