I’m porting an Android app to wp7 and I’m trying to do things the .net way, and I’m beginning to get my head wrapped around data binding, but I am lost when it comes to a few things.
My classes consist of the following:
- PickLeaf – the data representation of each item in the list
- PickLeafModel – the data representation of a collection of PickLeaf objects
- PickLeafCell – the user control for each item in the list
- PickLeafListView – derived version of ListBox
- PickLeafPage – the page that contains the list view and instantiates some of the controller objects and threads
- IPickLeafListener – an interface that the PickLeafPage implements and allows it to get notified when certain things occur regarding to the PickLeafCell (tap, context menu opened, scroll window changed)
Currently I am adding the PickLeafCell controls dynamically to PickLeafListView.Items, which kind of goes around data binding and perhaps is leading to some of the bugs I am seeing (such as updating it while its being scrolled causes scroll window to go berserk).
QUESTION: If I change it so that the PickLeafModel can be used as a DataSource, how do I pass the IPickLeafListener and PickLeaf references to the PickLeafCell using data binding?
Thanks!
It’s hard to understand your architecture, but I try.
First of all, bind your data to
ListBoxlistBox.ItemsSource = PickLeafModel;Your
ListBoxshould looks like:Two main thing happen here:
PickLeafCellDataContextis bind to your data for each list item. And you subscribe to yourPickLeafCellcustom events.When some event happens in
PickLeafCellcontrol, it raised custom event to which your main page is subscribedThis is your C# main page code-behind where you have event handlers:
And in
PickLeafCellcontrol you haveDataContextalready set to yourPickLeaf, so you can easy bind to fields