Style.Setters Özellik
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
ve Setter nesnelerinin EventSetter bir koleksiyonunu alır.
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
Özellik Değeri
ve Setter nesneleri koleksiyonuEventSetter. Varsayılan değer boş bir koleksiyondur.
Örnekler
Aşağıdaki örnekte bu özelliğin nasıl kullanılacağı gösterilmektedir.
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)
Bir SetterBase nesneye Style alt öğe eklemek, örtük olarak nesne için SetterBaseCollection öğesine eklerStyle. EventSetter Aşağıdakiler stile SetterBaseCollection örtük olarak eklenir:
<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>
Açıklamalar
Bir SettersStyle nesnenin özelliği yalnızca için SetterBaseatanabilir nesnelerden oluşabilir. Bir SetterBase nesneye Style alt öğe eklemek, örtük olarak nesne için SetterBaseCollection öğesine eklerStyle.
için Setters açık özellik öğesi kullanımı da nispeten yaygındır. Bu, bazen ve Setters öğelerini karmaşık bir stilde ayırt etmede ResourcesTriggers yardımcı olabilecek bir işaretleme stili kararıdır. Örneğin:
<Style>
<Style.Setters>
<!--one or more SetterBase derived object elements here-->
</Style.Setters>
</Style>
XAML Özellik Öğesi Kullanımı
<object>
oneOrMoreSetters
</object>
XAML Değerleri
oneOrMoreSetters Bir veya daha fazla Setter veya EventSetter nesne.