Control.Background Propriété
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Obtient ou définit un pinceau qui décrit l'arrière-plan d'un contrôle.
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
Le pinceau qui est utilisé pour remplir l'arrière-plan du contrôle. La valeur par défaut est Transparent.
- Attributs
L’exemple suivant montre comment définir la propriété d’arrière-plan d’un contrôle.
<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
L’exemple suivant montre un modèle qui permet à un déclencheur de modifier l’arrière-plan d’un bouton lorsqu’il est enfoncé.
<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>
La Background propriété s’applique uniquement à l’état de repos d’un contrôle. Le style par défaut du contrôle spécifie son apparence lorsque l’état du contrôle change. Par exemple, si vous définissez la Background propriété sur un Button, le bouton a cette valeur uniquement lorsqu’il n’est pas appuyé ou désactivé. Si vous souhaitez créer un contrôle qui a une personnalisation plus avancée de l’arrière-plan, vous devez définir le style du contrôle.
Cette propriété affecte uniquement un contrôle dont le modèle utilise la Background propriété comme paramètre. Sur d’autres contrôles, cette propriété n’a aucun impact.
Champ Identificateur | BackgroundProperty |
Propriétés de métadonnées définies sur true |
AffectsRender, SubPropertiesDoNotAffectRender |
Produit | Versions |
---|---|
.NET Framework | 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1 |
Windows Desktop | 3.0, 3.1, 5, 6, 7, 8, 9 |
Commentaires sur .NET
.NET est un projet open source. Sélectionnez un lien pour fournir des commentaires :