Style.Setters Property
Gets a collection of Setter and EventSetter objects.
Assembly: PresentationFramework (in PresentationFramework.dll)
XMLNS for XAML: http://schemas.microsoft.com/winfx/2006/xaml/presentation, http://schemas.microsoft.com/netfx/2007/xaml/presentation
<object> oneOrMoreSetters </object>
XAML Values
Property Value
Type: System.Windows.SetterBaseCollectionA 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:
<Style> <Style.Setters> <!--one or more SetterBase derived object elements here--> </Style.Setters> </Style>
The following example shows how to use this property.
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);
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:
<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>
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
As right now if I add a setter that already exist it crashes with a HRESULT E_FAIL from a COM component of Telerik c ontrol because I'm adding a setter that already exist. I've searched the web to find a solution and did not find it yet.
- 5/5/2011
- GearWorld