Style.Setters プロパティ

定義

Setter オブジェクトと EventSetter オブジェクトのコレクションを取得します。Gets a collection of Setter and EventSetter objects.

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

プロパティ値

SetterBaseCollection

Setter オブジェクトと EventSetter オブジェクトのコレクション。A collection of Setter and EventSetter objects. 既定値は空のコレクションです。The default is an empty collection.

このプロパティを使用する方法を次の例に示します。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);
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 Style 、オブジェクトのに暗黙的に子が追加さ SetterBaseCollection Style れます。Adding a SetterBase child to a Style object implicitly adds it to the SetterBaseCollection for the Style object. 次のは、 EventSetter スタイルのに暗黙的に追加され SetterBaseCollection ます。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>

注釈

Settersオブジェクトのプロパティは、 Style に割り当て可能なオブジェクトのみで構成でき SetterBase ます。The Setters property of a Style object can consist only of objects assignable to SetterBase. オブジェクトに子を追加すると SetterBase Style 、オブジェクトのに暗黙的に子が追加さ SetterBaseCollection Style れます。Adding a SetterBase child to a Style object implicitly adds it to the SetterBaseCollection for the Style object.

の明示的なプロパティ要素の使用 Setters も、比較的一般的です。An explicit property element usage for Setters is also relatively common. これは、 Setters Resources 複雑なスタイルの項目と項目を区別するために役立つ場合があるマークアップスタイルの決定です TriggersThis 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>  

XAML プロパティ要素の使用XAML Property Element Usage

<object>  
  oneOrMoreSetters  
</object>  

XAML 値XAML Values

Oneororg SetteroneOrMoreSetters
1つ以上 SetterEventSetter オブジェクトまたはオブジェクト。One or more Setter or EventSetter objects.

適用対象

こちらもご覧ください