Share via


Style.Setters Properti

Definisi

Mendapatkan koleksi Setter objek dan 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

Nilai Properti

Kumpulan Setter objek dan EventSetter . Defaultnya adalah koleksi kosong.

Contoh

Contoh berikut menunjukkan cara menggunakan properti ini.

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)

SetterBase Menambahkan anak ke Style objek secara implisit menambahkannya ke SetterBaseCollection objek Style . Berikut ini EventSetter secara implisit ditambahkan ke SetterBaseCollection gaya:

<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>

Keterangan

Properti SettersStyle objek hanya dapat terdiri dari objek yang dapat ditetapkan ke SetterBase. SetterBase Menambahkan anak ke Style objek secara implisit menambahkannya ke SetterBaseCollection objek Style .

Penggunaan elemen properti eksplisit untuk Setters juga relatif umum. Ini adalah keputusan gaya markup yang terkadang dapat membantu membedakan Setters dari Resources item dan Triggers dengan gaya yang kompleks. Contohnya:

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

Penggunaan Elemen Properti XAML

<object>
  oneOrMoreSetters
</object>

Nilai XAML

oneOrMoreSetters Satu atau beberapa SetterEventSetter objek.

Berlaku untuk

Lihat juga