この例では、ローカライズ可能なアプリケーションを作成するための自動レイアウト アプローチでグリッドを使用する方法について説明します。
ユーザー インターフェイス (UI) のローカライズには時間がかかる場合があります。 多くの場合、ローカライザーは、テキストの翻訳に加えて、要素のサイズと位置を変更する必要があります。 以前は、UI を各言語に適応させるために調整が必要でした。 Windows Presentation Foundation (WPF) の機能を使用して、調整の必要性を減らす要素を設計できるようになりました。 より簡単にサイズを変更して再配置できるアプリケーションを記述するアプローチは、auto layout
と呼ばれます。
次の拡張アプリケーション マークアップ言語 (XAML) の例は、グリッドを使用してボタンとテキストを配置する方法を示しています。 セルの高さと幅が Auto
に設定されていることに注意してください。そのため、画像を含むボタンを含むセルは、画像に合わせて調整されます。
Grid 要素はコンテンツに合わせて調整できるため、ローカライズ可能なアプリケーションを設計するための自動レイアウト アプローチを使用する場合に便利です。
例
次の例は、グリッドの使用方法を示しています。
<Grid Name="grid" ShowGridLines ="false">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<TextBlock Margin="10, 10, 5, 5" Grid.Column="0" Grid.Row="0" FontSize="24">Grid
</TextBlock>
<TextBlock Margin="10, 10, 5, 5" Grid.Column="0" Grid.Row="1" FontSize="12"
Grid.ColumnSpan="2">The following buttons and text are positioned using a Grid.
</TextBlock>
<Button Margin="10, 10, 5, 5" Grid.Column="0" Grid.Row="2" Background="Pink"
BorderBrush="Black" BorderThickness="10">Button 1
</Button>
<TextBlock Margin="10, 10, 5, 5" Grid.Column="1" Grid.Row="2" FontSize="12"
VerticalAlignment="Center" TextWrapping="WrapWithOverflow">Sets the background
color.
</TextBlock>
<Button Margin="10, 10, 5, 5" Grid.Column="0" Grid.Row="3" Foreground="Red">
Button 2
</Button>
<TextBlock Margin="10, 10, 5, 5" Grid.Column="1" Grid.Row="3" FontSize="12"
VerticalAlignment="Center" TextWrapping="WrapWithOverflow">Sets the foreground
color.
</TextBlock>
<Button Margin="10, 10, 5, 5" Grid.Column="0" Grid.Row="4">
<Image Source="data\flower.jpg"></Image>
</Button>
<TextBlock Margin="10, 10, 5, 5" Grid.Column="1" Grid.Row="4" FontSize="12"
VerticalAlignment="Center" TextWrapping="WrapWithOverflow">Adds an image as
the button's content.
</TextBlock>
</Grid>
次の図は、コード サンプルの出力を示しています。
の例
グリッド
こちらも参照ください
- 自動レイアウトの使用の概要
- 自動レイアウトを使用してボタン を作成する
.NET Desktop feedback