Why Attached Properties of a DocumentWindow are not inherited by content elements?

Docking/MDI for WPF Forum

Posted 11 years ago by Andras Eles
Version: 12.2.0572

I am trying to add an attached propety to a DocumentWindow that is inherited by the UIElements of its content.

The attached property is declared like this:

DependencyProperty.RegisterAttached("MyProperty", typeof(IMyProperty), typeof(MyAttachedProperties), new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.Inherits));

The Document Window is created in code and the attached property is immediately set. Then I define the UI Elements for the window and display it.

When I Snoop the (MDI) application I see my property has the correct value on the DocumentWindow but not on the related PART_SelectedContentHost or its children.

Comments (4)

Answer - Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA

Hi Andras,

The DocumentWindow is represented in UI by the tab that is rendered for it.  Since the window's content ends up being presented elsewhere (within a TabbedMdiContainer, etc.), it might not get the inherited value.  You probably want to set the attached property on the root element of your content instead to make sure it inherits properly.

Actipro Software Support

Posted 11 years ago by Andras Eles

I got it working. 

Originally I followed the MVVM pattern and created my view model in code. I assigned this view model to the DataContext and also bind it to the Content property of the DocumentWindow. I also had a DataTemplate under Themes\Generic.xaml that maped the type of my view model to the view.

This approach works fine except the inherited attached properties.

The workaround is to create the view model in code, assign it to the DataContext of the DocumentWindow. Then create the view and assign it to the Content.

Posted 11 years ago by Andras Eles


The application now runs no problem but I lost the ability to unit test the class that creates the view. Earlier it was possible since the Content was bind to a view model.

Can you explain me why attached property inheritance works in my workaround and not in the original solution?

Posted 11 years ago by Actipro Software Support - Cleveland, OH, USA

I'm not sure.  Can you expose some property on your view model and then on the root Control you assign as your View in the DataTemplate, set the attached property on that by binding (with appropriate value conversion) to the property in your VM?

Actipro Software Support

The latest build of this product (v24.1.2) was released 2 months ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.