Grid: wiersze i kolumny
Układ okna: Grid, StackPanel i ramki - Aplikacje desktopowe: WPF krok po kroku (wpf)
Grid.ColumnDefinitions i Grid.RowDefinitions opisują kolumny i wiersze siatki. Width="Auto" to tyle, ile potrzebuje treść, * to cała reszta miejsca. Każda kontrolka mówi, gdzie stoi: Grid.Row="1" Grid.Column="1" (numeracja od 0, brak atrybutu = 0). Zobacz siatkę w widoku Projekt.MainWindow.xaml
<Window x:Class="WpfApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Formularz" Height="180" Width="320">
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Label Content="Imię:"/>
<TextBox Grid.Column="1" Margin="0,4"/>
<Label Grid.Row="1" Content="E-mail:"/>
<TextBox Grid.Row="1" Grid.Column="1" Margin="0,4"/>
<Button Grid.Row="2" Grid.Column="1" Content="Wyślij" Width="80" HorizontalAlignment="Right"/>
</Grid>
</Window>MainWindow.xaml.cs
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace WpfApp
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}Ładowanie interaktywnego edytora... Jeśli się nie pojawi, włącz JavaScript.
Wszystkie lekcje kursu Aplikacje desktopowe: WPF krok po kroku·Zaloguj się, aby zapisać postęp na koncie.