DataBinding the New Button

DataBinding the New Button

Old forum URL: forums.lhotka.net/forums/t/5627.aspx


rossl123 posted on Monday, October 20, 2008

Hi,
I am trying to come to grips with the new WPF technology and how it all works with CSLA 3.6 with a mind to converting my existing Win Forms/CSLA1.1 app.

My specific problem is to do with setting up a new BO instance in a WPF window. My current screen design usually includes a listbox or treeview control on the left side of the window that displays the BO collection, and is used for navigating between instances. The listbox is bound to the BO Collection declaritively using a csladataprovider. On the right side of the window I show BO instances, whose fields are bound to the BO selected in the listbox using a separate dataprovider to which I set the ManageObjectLifetime property True. I know that this is not the design used in the ProjectTracker sample (Is there a new one for WPF yet?), but it is the way my users like to work with their data, and it is the current design of my entire app, so I have to find a way to get it to work, or rewrite everything.

The current layout for my windows works fine in all respects except in the case of adding new items.
If I use ApplicationCommands behind the New button, and target the BO collection dataprovider, I get a new BO instance loaded into the collection, and it appears in my listbox, but I can't get the listbox SelectedItem property to set to the new BO as part of the same event, and consequently the detail section of my window doesnt get rebound to my new BO either. If I add code to the New buttons Click event it fires before the new BO gets created, and if I catch the DataChanged event for the dataprovider it only seems to fire when the collection is created, or when an item is deleted out of it.

How can I get this to work?

RockfordLhotka replied on Monday, October 20, 2008

I noticed that same issue when mixing commanding and events - the events go first, then commanding. It seems like buttons need a Clicking event, then the command should go, then the Click event. Or perhaps they need a Clicked event after the command.

There may be an elegant answer, but I don't know it. :(

One solution may be to create your own Button control (subclass Button) that does raise a Clicked event. I haven't done this, but it seems like it might work.

rossl123 replied on Wednesday, October 22, 2008

Rocky

Thanks for your reply, I think you are right, a Clicked event would be nice to have.

A couple of further thoughts have come to mind. Perhaps it would work handling the Click event after it has bubbled up to the Window level?

Also, have you had any experience with class extension methods? I have just been reading about them here and it seems they could be just the ticket.

regards
Ross

Copyright (c) Marimer LLC