Take the 2-minute tour ×

I have the following situation:

  1. I have a User Control with just a single Grid inside.
  2. The Grid has its first column as a checkbox column, which is bound to the IsSelected property of CustomerModel
  3. ItemsSource for the Grid is bound to List< CustomerModel>
  4. When the user checks any of the CheckBoxes the corresponding IsSelected property of CustomerModel is getting updated


  1. I added a dependency property to the UserControl named "SelectedCustomerItems", and I want it to return a List< CustomerModel> (Only for IsSelected = true)

  2. This UserControl is placed on another Window

  3. The Dependency Property "SelectedCustomerItems" is bound to "SelectedCustomers" property inside the WindowViewModel

But I am not getting the SelectedCustomer Items through this dependency property. Breakpoint is not hitting in Get{} Please suggest....

share|improve this question
Just wrap the CustomerModel in a CustomerViewModel which contains the IsSelected property. You don't need to put DependencyProperties in the UI to hold your data. –  HighCore Mar 26 '13 at 20:45
Thanks HiCore, I already have it. The issue i am facing is: When i give this User Control to another User, how can he get SelectedCustmerItems from the UserControl into his ViewModel –  user1386121 Mar 26 '13 at 21:00
"Selected / Non Selected" is not a responsibility of the View (IMO). Rather, have a CheckBox bound to the IsSelected property of the thing. Then it's a matter of .Where(x => X.IsSelected). –  HighCore Mar 26 '13 at 21:07
I am agree. I just want another User to read all Selected data from my user control. How to do it. –  user1386121 Mar 26 '13 at 21:18
Sorry, you don't seem to understand. Please post your current code and XAML, so I can tell you how to fix it. –  HighCore Mar 26 '13 at 21:20
show 1 more comment

1 Answer

Implement your DPs this way:

#region SomeProperty
/// <summary>
/// The <see cref="DependencyProperty"/> for <see cref="SomeProperty"/>.
/// </summary>
public static readonly DependencyProperty SomePropertyProperty =
        // other types here may be appropriate for your situ
        new FrameworkPropertyMetadata(null, OnSomePropertyPropertyChanged));

/// <summary>
/// Called when the value of <see cref="SomePropertyProperty"/> changes on a given instance of <see cref="SomeType"/>.
/// </summary>
/// <param name="d">The instance on which the property changed.</param>
private static void OnSomePropertyPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    (d as SomeType).OnSomePropertyChanged(e.OldValue as object, e.NewValue as object);

/// <summary>
/// Called when <see cref="SomeProperty"/> changes.
/// </summary>
/// <param name="oldValue">The old value</param>
/// <param name="newValue">The new value</param>
private void OnSomePropertyChanged(object oldValue, object newValue)


/// <summary>
/// The name of the <see cref="SomeProperty"/> <see cref="DependencyProperty"/>.
/// </summary>
public const string SomePropertyPropertyName = "SomeProperty";

/// <summary>
/// </summary>
public object SomeProperty
    get { return (object)GetValue(SomePropertyProperty); }
    set { SetValue(SomePropertyProperty, value); }

You must understand that a DependencyProperty isn't just a property with a bunch of junk added, its a hook into the WPF Binding system. This is a vast, complex system that lives below the sea level upon which your DP daintily floats. It behaves in ways that you will not expect, unless you actually learn it.

You are experiencing the first revelation all of us had with DPs: Bindings do NOT access DependencyProperty values via the property accessors (i.e., get and set methods). These property accessors are convenience methods for you to use from code only. You could dispense with them and use DependencyObject.GetValue and DependencyObject.SetValue, which are the actual hooks into the system (see the implementation of the getters/setters in my example above).

If you want to listen for change notification, you should do what I have done above in my example. You can add a change notification listener when registering your DependencyProperty. You can also override the "Metadata" of inherited DependencyProperties (I do this all the time for DataContext) in order to add change notification (some use the DependencyPropertyDescriptor for this, but I've found them to be lacking).

But, whatever you do, do NOT add code to the get and set methods of your DependencyProperties! They won't be executed by binding operations.

For more information about how DependencyProperties work, I highly suggest reading this great overview on MSDN.

share|improve this answer
add comment

Your Answer


