views:

236

answers:

2

hi,

I created a custom control that internally is using BindingList to keep track of Account objects that are displayed in some custom grid. I want to add a DependencyProperty to my control that will expose set/get for List that will allow me TwoWay binding between my control and data model. I want to be able to set that list to initialize my control, and get updates resulting from updates to BindingList. In short I need to somehow provide a translation between the List from DependencyProperty and my internal BindingList and vice versa (depending whether my control is initially bound from the data source, or the data source is updated based on changes to BindingList in my control).

The examples that I found on the web deal with controls working directly with lists set on DependencyProperties - In my case I want to have a level of indirecion as the BindingList is not necessarly the same as list from DependencyProperty.

A: 

How come BindingList is not the same? That's not how C# works:

myControl1.List = list1;

The meaning of above by definition is set property to value, it is supposed to be the same after set.

While you can create a funny logic in the setter of general plain C# class, DependencyProperty is predefined concept and there you won't be able to divert from sanity.

Oleg Mihailik
A: 

The BindingList that I'm using internally is not the same as the list on the DependencyProperty that I'm trying to expose because I don't want to expose internal implementation to external property.

In complex controls there may be multiple grids, etc that need to have their own BindingLists to hold data. My DependencyProperty is to be used to: 1) initialize the custom control with some data 2) set new list based on user input back to the model.