Click or drag to resize
Sandcastle Help File BuilderDocumenting WPF Attached Properties and Events

This topic describes how you can document the compiler-generated attached property and attached event members in WPF classes.

Because the attached property and attached event members of WPF classes are compiler-generated, there is no way to associate XML comments with them directly without managing a standalone XML comments file. While it is possible to do this, it is less convenient than keeping the comments in the code. The help file builder provides a solution to this through its GenerateInheritedDocs tool. As part of the process of generating inherited documentation, the tool will look for attached property and attached event fields. If it finds them, it will automatically inherit their comments for the related compiler-generated members as default comments to prevent a "missing comments" warning.

In addition, if it finds comments for those field members, it will check for an AttachedPropertyComments element (for attached properties) or an AttachedEventComments element (for attached events) and, if found, will use the XML comments nested within those elements for the related compiler-generated members. This allows you to provide comments for the field member and the related compiler-generated member that are entirely different but are managed from within the code. Below are examples of an attached property and an attached event with the extra comments for the compiler-generated members. The Sandcastle XML Comments Guide installed as part of the Sandcastle tools contains working examples that you look at to see the end result.

Note Note

Because the attached property and event members are compiler-generated, you must fully qualify their names if you want to create a link to them with a see element as shown in the examples below.

Attached Property Comments Example
/// <summary>
/// This defines the <see cref="P:TestDoc.TestClass.IsBroughtIntoViewWhenSelected"/>
/// attached property.
/// </summary>
///
/// <AttachedPropertyComments>
/// <summary>This attached property indicates whether or not a tree view item is
/// brought into view when selected.
/// </summary>
/// <value>The default value is false</value>
/// </AttachedPropertyComments>
public static readonly DependencyProperty IsBroughtIntoViewWhenSelectedProperty =
    DependencyProperty.RegisterAttached("IsBroughtIntoViewWhenSelected",
    typeof(bool), typeof(TestClass),
    new UIPropertyMetadata(false, OnIsBroughtIntoViewWhenSelectedChanged));
Attached Event Comments Example
/// <summary>
/// This defines the <see cref="E:TestDoc.TestClass.ItemActivate"/>
/// attached event.
/// </summary>
///
/// <AttachedEventComments>
/// <summary>
/// This attached event is raised when an item is activated
/// </summary>
/// <remarks>There's a bit more too it to get the event raised but this is just a
/// documentation example.</remarks>
/// </AttachedEventComments>
public static readonly RoutedEvent ItemActivateEvent = EventManager.RegisterRoutedEvent(
    "ItemActivate", RoutingStrategy.Bubble, typeof(RoutedEventHandler),
    typeof(TestClass));
See Also