Lance
Lance

Reputation: 611

WPF Property Binding Source Property not being Accessed

I am attempting to bind a dependency property on a control that inherits from MenuItem to a dependency property of my window. I've put break points on the get and sets of both properties and I never see the property get of the window being called. The window property is the source and the control property is the target.

The property of the control looks like this:

Public Shared StorageProperty As DependencyProperty = 
                                 DependencyProperty.Register("Storage",
                                                             GetType(IStorage),
                                                             GetType(MRUFileList),
                                                             New PropertyMetadata(Nothing))

Public Property Storage As IStorage
    Get
        Return DirectCast(GetValue(StorageProperty), IStorage)
    End Get
    Set(value As IStorage)
        SetValue(StorageProperty, value)
    End Set
End Property

And the property of the window is:

Public Shared ReadOnly MRUStorageProperty As DependencyProperty =
                                             DependencyProperty.Register("MRUStorage",
                                                                         GetType(MRU.IStorage),
                                                                         GetType(GrammarEditor),
                                                                         New PropertyMetadata(Nothing))

Public Property MRUStorage As MRU.IStorage
    Get
        Return DirectCast(GetValue(MRUStorageProperty), MRU.IStorage)
    End Get
    Set(value As MRU.IStorage)
        SetValue(MRUStorageProperty, value)
    End Set
End Property

And lastly, the XAML defining the binding is:

<mru:MRUFileList Name="mnuRecent" 
                 Header="Open _Recent" 
                 Storage="{Binding MRUStorage, 
                           Mode=TwoWay, 
                           UpdateSourceTrigger=PropertyChanged}" />

Previously I have tried to set the RelativeSource to Self and also to FindAncestor with AncestoryType set to Window.

Upvotes: 0

Views: 136

Answers (1)

ndonohoe
ndonohoe

Reputation: 10230

With a dependency property binding the get/set will never be called because the binding is resolved using the dependency property infrastructure. As you can see all your property does is allow you easy access to the value of that dependency property by calling

GetValue(StorageProperty)

Instead of using your property the binding engine just calls that directly

edit: Does your window have MRUStorage as a property? You will need that to be able to use it as a binding path

Upvotes: 1

Related Questions