概要
WPF の GroupBox コントロールは、関連するコントロールをまとめて表示する際に役立ちます。GroupBox コントロールの背景色を設定するには、Background プロパティを使用できます。
このブログ記事では、Background プロパティを使用して、GroupBox コントロールの背景色を設定する方法について説明します。
構文
XAML
<GroupBox Header="グループボックス" Background="背景色"> ... </GroupBox>
Background
プロパティ: グループボックスの背景色を設定します。
コードビハインド
var groupBox = new GroupBox(); groupBox.Header = "グループボックス"; groupBox.Background = new SolidColorBrush(Colors.Red); // ... this.Content = groupBox;
Background
プロパティ: グループボックスの背景色を設定します。
実行例
XAML
<GroupBox Header="グループボックス"> <GroupBox.Background> <LinearGradientBrush StartPoint="0,0" EndPoint="1,1"> <GradientStop Color="Red" Offset="0.0" /> <GradientStop Color="Blue" Offset="1.0" /> </LinearGradientBrush> </GroupBox.Background> ... </GroupBox>
背景色は LinearGradientBrush を使用することでグラデーションにすることもできます。
コードビハインド
var groupBox = new GroupBox(); groupBox.Header = "グループボックス"; var linearGradientBrush = new LinearGradientBrush(); linearGradientBrush.StartPoint = new Point(0, 0); linearGradientBrush.EndPoint = new Point(1, 1); var gradientStop1 = new GradientStop(); gradientStop1.Color = Colors.Red; gradientStop1.Offset = 0.0; var gradientStop2 = new GradientStop(); gradientStop2.Color = Colors.Blue; gradientStop2.Offset = 1.0; linearGradientBrush.GradientStops.Add(gradientStop1); linearGradientBrush.GradientStops.Add(gradientStop2); groupBox.Background = linearGradientBrush; // ... this.Content = groupBox;
まとめ
このブログ記事では、WPF の GroupBox コントロールの Background プロパティと HeaderAlignment プロパティを使用して、タイトルと背景色を設定する方法について説明しました。
Please follow and like us:
コメント