Style.Setters Propiedad

Definición

Obtiene una colección de objetos Setter y EventSetter.

public:
 property System::Windows::SetterBaseCollection ^ Setters { System::Windows::SetterBaseCollection ^ get(); };
public System.Windows.SetterBaseCollection Setters { get; }
member this.Setters : System.Windows.SetterBaseCollection
Public ReadOnly Property Setters As SetterBaseCollection

Valor de propiedad

SetterBaseCollection

Colección de objetos Setter y EventSetter. El valor predeterminado es una colección vacía.

Ejemplos

En el ejemplo siguiente se muestra cómo usar esta propiedad.

Style style = new Style(typeof(ListBoxItem));
style.Setters.Add(new Setter(ListBoxItem.HorizontalContentAlignmentProperty,
     HorizontalAlignment.Stretch));
ListBox lb = new ListBox();
lb.ItemContainerStyle = style;
ListBoxItem lbi1 = new ListBoxItem();
Button btn = new Button();
btn.Content = "Button as styled list box item.";
lbi1.Content = (btn);
lb.Items.Add(lbi1);
Dim style As Style = New Style()
style.Setters.Add(New Setter(ListBoxItem.HorizontalContentAlignmentProperty, _
     HorizontalAlignment.Stretch))
Dim lb As ListBox = New ListBox()
lb.ItemContainerStyle = style
Dim lbi1 As ListBoxItem = New ListBoxItem()
Dim btn As Button = New Button()
btn.Content = "Button as styled list box item."
lbi1.Content = (btn)
lb.Items.Add(lbi1)

Agregar un SetterBase elemento secundario a un Style objeto lo agrega implícitamente al SetterBaseCollection objeto para el Style objeto . A continuación EventSetter se agrega implícitamente al SetterBaseCollection del estilo :

<StackPanel
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  x:Class="SDKSample.EventOvw2"
  Name="dpanel2"
  Initialized="PrimeHandledToo"
>
  <StackPanel.Resources>
    <Style TargetType="{x:Type Button}">
      <EventSetter Event="Click" Handler="b1SetColor"/>
    </Style>
  </StackPanel.Resources>
  <Button>Click me</Button>
  <Button Name="ThisButton" Click="HandleThis">
    Raise event, handle it, use handled=true handler to get it anyway.
  </Button>
</StackPanel>

Comentarios

La Setters propiedad de un Style objeto solo puede constar de objetos asignables a SetterBase. Agregar un SetterBase elemento secundario a un Style objeto lo agrega implícitamente al SetterBaseCollection objeto para el Style objeto .

Un uso explícito de elementos de propiedad para Setters también es relativamente común. Se trata de una decisión de estilo de marcado que a veces puede ayudar a distinguir Setters elementos y Resources Triggers de un estilo complejo. Por ejemplo:

<Style>  
  <Style.Setters>  
    <!--one or more SetterBase derived object elements here-->  
  </Style.Setters>  
</Style>  

Uso de elementos de propiedad XAML

<object>  
  oneOrMoreSetters  
</object>  

Valores XAML

oneOrMoreSetters
Uno o varios Setter objetos.EventSetter

Se aplica a

Consulte también