Udostępnij za pośrednictwem


Setter.Value Property

Definition

Gets or sets the value to apply to the property that is specified by the Setter.

public:
 property Platform::Object ^ Value { Platform::Object ^ get(); void set(Platform::Object ^ value); };
IInspectable Value();

void Value(IInspectable value);
public object Value { get; set; }
var object = setter.value;
setter.value = object;
Public Property Value As Object
<Setter ...>
  <Setter.Value>
    objectValue
  </Setter.Value>
</Setter>
- or -
<Setter Value="attributeValue"/>
-or-
<Setter Value="extensionUsage"/>

Property Value

Object

Platform::Object

IInspectable

The value to apply to the property that is specified by the Setter.

Remarks

As you can see from the XAML syntax, there are a variety of ways to specify the Value for a Setter in XAML:

  • As an attribute, using a string value. Such a string value can be implicitly converted to a property-specific type for simple cases such as setting numeric values, named values from an enumeration, or a Uniform Resource Identifier (URI).
  • As a complete new object that's declared in XAML object element syntax, and the object element is nested within a property element usage.
  • As an attribute that has a {StaticResource} markup extension usage within the quotes. Typically the value type of the property dictates which syntax is appropriate. For more info on XAML usages, see XAML overview or XAML syntax guide. You can use attribute syntax for most XAML UI properties, and UI properties that specifically require a property element usage or a resource reference are less common. A {StaticResource} markup extension usage can be appropriate even for strings or numeric values if those values are shared by more than one style or property.

You must specify both the Property and Value properties on a Setter. Otherwise an exception is thrown (either a parse exception or runtime error, depending on whether the Setter is created in XAML or modified in code).

If you're accessing a Setter instance using code, you cannot change the value of any property of a Setter instance if the value of the IsSealed property on a parent Style is true. This is also reported by the IsSealed property on an individual Setter. The system sets these properties to true when the runtime applies styles to UI elements and displays them in the UI. Attempting to change a sealed Setter throws a runtime error.

Styles and templates

You can use a Setter in a Style to apply values to any dependency property. But it's the Setter for the Template property of a Control-derived class that constitutes the majority of the XAML markup in a typical Style. The Value for a Setter with Property="Template" is almost always specified as a property element that contains a ControlTemplate object element.

When a Style is used to define a control template, the TargetType of the Style element and the TargetType of the ControlTemplate element for its Control.Template setter should always use the same value.

The Template setter defines the basic template UI definition for a control instance where that template is applied. It also contains the visual states for a control, and other state-based UI definitions such as default theme transitions. For a complex control such as ListBox, the default template Style and the ControlTemplate within can have hundreds of lines of XAML. For more info on the role of Style in control templating scenarios, see Quickstart: Control templates.

Applies to