Value property
Collapse the table of content
Expand the table of content

Setter.Value property

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

Syntax


Public Property Value As Object


<Setter ...>
  <Setter.Value>
    objectValue
  </Setter.Value>
</Setter>


<Setter Value="attributeValue"/>
-or-
<Setter Value="extensionUsage"/>

XAML Values

objectValue

An object element that specifies the value of the property being set.

attributeValue

A string that specifies the attribute value of the property being set. The format and interpretation of the string provided for the attribute value depends on the property being set.

extensionUsage

One of several possible extension mechanisms that specify the property value to be obtained from an existing value. The most common of these is {StaticResource} markup extension.

Property value

Type: System.Object [.NET] | Platform::Object [C++]

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.

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.UI.Xaml
Windows::UI::Xaml [C++]

Metadata

Windows.winmd

See also

Setter

 

 

Show:
© 2017 Microsoft