This topic contains the following sections.
- GetValue and SetValue
- Attached Properties in WPF and Managed Code
- Related Topics
GetValue and SetValue
Attached Properties in WPF and Managed Code
It may be useful to provide some background on the attached property usages that are available for WPF and managed code. In managed code, the XAML parser uses a discovery pattern for determining the accessors for attached properties, in order to process the values. The discovery pattern is based on methods named Get* and Set*, and is described in the XAML language specifications (though the managed specifics of the WPF implementation are not described there).
The most important aspect to note here is that in both the GetValue/SetValue notations and the abridged notation, the . (dot) is considered part of the property name/identifier, and must be within the quotes. The following example shows the various syntaxes through usage:
// Set the value using the ["attachedPropertyName"] notation. anObject["Canvas.Top"] = 40; // Set the value using the SetValue method. anObject2.setValue("Canvas.Top", 40); // Get the value using the ["attachedPropertyName"] notation. var top = anObject["Canvas.Top"]; // Get the value using the GetValue method. var top2 = anObject2.GetValue("Canvas.Top");