RelativeSource.Self Property

Definition

Gets a static value that is used to return a RelativeSource constructed for the Self mode.

public:
 static property System::Windows::Data::RelativeSource ^ Self { System::Windows::Data::RelativeSource ^ get(); };
public static System.Windows.Data.RelativeSource Self { get; }
static member Self : System.Windows.Data.RelativeSource
Public Shared ReadOnly Property Self As RelativeSource

Property Value

A static RelativeSource.

Examples

The following example shows a style trigger that creates a ToolTip that reports a validation error message. The value of the setter binds to the error content of the current TextBox (the TextBox using the style) using the RelativeSource property. See How to: Implement Binding Validation for more information on this example.

<Style x:Key="textBoxInError" TargetType="{x:Type TextBox}">
  <Style.Triggers>
    <Trigger Property="Validation.HasError" Value="true">
      <Setter Property="ToolTip"
        Value="{Binding RelativeSource={x:Static RelativeSource.Self},
                        Path=(Validation.Errors)/ErrorContent}"/>
    </Trigger>
  </Style.Triggers>
</Style>

Remarks

Three of the four RelativeSourceMode values, PreviousData, Self, or TemplatedParent, can produce a RelativeSource that is wholly static, containing no unique private values. All uses of the static property can share the same object, eliminating the need to allocate separate objects for each use. Therefore, using the static property reduces memory usage.

XAML Text Usage

For XAML information, see RelativeSource MarkupExtension.

Applies to

See also