Style.Setters 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得 Setter 與 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
屬性值
Setter 與 EventSetter 物件的集合。 預設為空集合。
範例
下列範例示範如何使用這個屬性。
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 。 下列內容 EventSetter 會隱含新增至 SetterBaseCollection 樣式的 :
<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 屬性只能包含可指派給 SetterBase的物件Style。 SetterBase將子系新增至 Style 物件,會隱含地將它新增至 SetterBaseCollection 物件的 Style 。
的明確屬性元素使用 Setters 方式也相當常見。 這是標記樣式決策,有時有助於區分SettersResources複雜樣式中的和 Triggers 專案。 例如:
<Style>
<Style.Setters>
<!--one or more SetterBase derived object elements here-->
</Style.Setters>
</Style>
XAML 屬性項目用法
<object>
oneOrMoreSetters
</object>
XAML 值
oneOrMoreSetters 一或多個 Setter 或 EventSetter 物件。