Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Style.Setters Property

Gets a collection of Setter and EventSetter objects.

Namespace:  System.Windows
Assembly:  PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation

public SetterBaseCollection Setters { get; }

XAML Values


One or more Setter or EventSetter objects.

Property Value

Type: System.Windows.SetterBaseCollection
A collection of Setter and EventSetter objects. The default is an empty collection.

The Setters property of a Style object can consist only of objects assignable to SetterBase. Adding a SetterBase child to a Style object implicitly adds it to the SetterBaseCollection for the Style object.

An explicit property element usage for Setters is also relatively common. This is a markup style decision that can sometimes help distinguish Setters from Resources and Triggers items in a complex style. For example:

    <!--one or more SetterBase derived object elements here-->

The following example shows how to use this property.

Style style = new Style(typeof(ListBoxItem));
style.Setters.Add(new Setter(ListBoxItem.HorizontalContentAlignmentProperty,
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);

Adding a SetterBase child to a Style object implicitly adds it to the SetterBaseCollection for the Style object. The following EventSetter is implicitly added to the SetterBaseCollection of the style:

    <Style TargetType="{x:Type Button}">
      <EventSetter Event="Click" Handler="b1SetColor"/>
  <Button>Click me</Button>
  <Button Name="ThisButton" Click="HandleThis">
    Raise event, handle it, use handled=true handler to get it anyway.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
© 2015 Microsoft