Control.Background 속성
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
컨트롤의 배경을 설명하는 브러시를 가져오거나 설정합니다.
public:
property System::Windows::Media::Brush ^ Background { System::Windows::Media::Brush ^ get(); void set(System::Windows::Media::Brush ^ value); };
[System.ComponentModel.Bindable(true)]
public System.Windows.Media.Brush Background { get; set; }
[<System.ComponentModel.Bindable(true)>]
member this.Background : System.Windows.Media.Brush with get, set
Public Property Background As Brush
속성 값
컨트롤의 배경을 채우는 데 사용되는 브러시입니다. 기본값은 Transparent입니다.
- 특성
예제
다음 예제에서는 컨트롤의 백그라운드 속성을 설정 하는 방법을 보여 있습니다.
<Button Name="btn" Background="Red"
Click="ChangeBackground">
Background
</Button>
void ChangeBackground(object sender, RoutedEventArgs e)
{
if (btn.Background == Brushes.Red)
{
btn.Background = new LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90);
btn.Content = "Control background changes from red to a blue gradient.";
}
else
{
btn.Background = Brushes.Red;
btn.Content = "Background";
}
}
Private Sub ChangeBackground(ByVal Sender As Object, ByVal e As RoutedEventArgs)
If (Equals(btn.Background, Brushes.Red)) Then
btn.Background = New LinearGradientBrush(Colors.LightBlue, Colors.SlateBlue, 90)
btn.Content = "Control background changes from red to a blue gradient."
Else
btn.Background = Brushes.Red
btn.Content = "Background"
End If
End Sub
다음 예제에서는 트리거를 누를 때 단추의 배경을 변경할 수 있도록 하는 템플릿을 보여 줍니다.
<Button FontSize="16" FontWeight="Bold">Click the Background
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border Background="{TemplateBinding Background}">
<ContentPresenter/>
</Border>
</ControlTemplate>
</Button.Template>
<Button.Style>
<Style TargetType="{x:Type Button}">
<Setter Property="Background" Value="Blue"/>
<Style.Triggers>
<Trigger Property="IsPressed" Value="true">
<Setter Property="Background" Value="Red"/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
</Button>
설명
이 속성은 Background 컨트롤의 나머지 상태에만 적용됩니다. 컨트롤의 기본 스타일은 컨트롤 상태가 변경되면 모양을 지정합니다. 예를 들어 속성에 BackgroundButton설정하면 단추는 눌리거나 사용하지 않도록 설정되지 않은 경우에만 해당 값을 가집니다. 배경의 고급 사용자 지정이 있는 컨트롤을 만들려면 컨트롤의 스타일을 정의해야 합니다.
이 속성은 템플릿이 속성을 매개 변수로 사용하는 컨트롤에 Background 만 영향을 줍니다. 다른 컨트롤에서 이 속성은 영향을 주지 않습니다.
종속성 속성 정보
| Item | 가치 |
|---|---|
| 식별자 필드 | BackgroundProperty |
메타데이터 속성이 다음으로 설정됩니다. true |
AffectsRender, SubPropertiesDoNotAffectRender |