Setter.Property Property

July 28, 2014

Gets or sets the property to apply the Value to.

Namespace:  System.Windows
Assembly:  System.Windows (in System.Windows.dll)
XMLNS for XAML: Not mapped to an xmlns.

public DependencyProperty Property { get; set; }
<Setter Property="propertyName"/>

XAML Values

propertyName

A string that specifies the name of the property being set. This property must be a dependency property.

Property Value

Type: System.Windows.DependencyProperty
A DependencyProperty to which the Value will be applied. The default is null.

You must specify both the Property and Value properties on a Setter or an exception is thrown.

You cannot change this property if IsSealed is true.

The following example creates two styles: one for a TextBlock and one for a TextBox. The style for the TextBlock sets the Foreground, FontSize, and VerticalAlignment properties. The style for the TextBox sets the Width, Height, Margin, Background, and FontSize properties. Each style is applied to two instances of a control to create a uniform appearance for each TextBlock and TextBox.


<StackPanel>
  <StackPanel.Resources>
      <!--Create a Style for a TextBlock that uses some 
          values from the Theme Resources for Windows Phone 
          (http://msdn.microsoft.com/en-us/library/ff769552(v=VS.92).aspx).-->
      <Style TargetType="TextBlock" x:Key="TextBlockStyle">
              <Setter Property="Foreground" Value="{StaticResource PhoneSubtleColor}"/>
              <Setter Property="Margin" Value="{StaticResource PhoneMargin}"/>
              <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/>
      <Setter Property="VerticalAlignment" Value="Center"/>
      </Style>

      <!--Create a Style for a TextBox that uses some 
          values from the Theme Resources for Windows Phone 
          (http://msdn.microsoft.com/en-us/library/ff769552(v=VS.92).aspx).-->
      <Style TargetType="TextBox" x:Key="TextBoxStyle">
          <Setter Property="Width" Value="300"/>
          <Setter Property="Height" Value="70"/>
          <Setter Property="Margin" Value="{StaticResource PhoneMargin}"/>
          <Setter Property="FontSize" Value="{StaticResource PhoneFontSizeMedium}"/>
          <Setter Property="Background" Value="{StaticResource PhoneAccentColor}" />
    </Style>
  </StackPanel.Resources>

  <!--Apply the TextBlockStyle and TextBoxStyle to each 
          TextBlock and TextBox, respectively.-->
  <StackPanel Orientation="Horizontal">
    <TextBlock Style="{StaticResource TextBlockStyle}">
              First Name:
          </TextBlock>
    <TextBox Style="{StaticResource TextBoxStyle}"/>
  </StackPanel>
  <StackPanel Orientation="Horizontal">
    <TextBlock Style="{StaticResource TextBlockStyle}">
              Last Name:
          </TextBlock>
    <TextBox Style="{StaticResource TextBoxStyle}" />
  </StackPanel>
</StackPanel>


Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Show:
© 2014 Microsoft