New Posts New Posts RSS Feed: WPF-binding to Navigation Properties
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

WPF-binding to Navigation Properties

 Post Reply Post Reply
Author
allo View Drop Down
Newbie
Newbie
Avatar

Joined: 27-Oct-2008
Location: Toronto, ON
Posts: 7
Post Options Post Options   Quote allo Quote  Post ReplyReply Direct Link To This Post Topic: WPF-binding to Navigation Properties
    Posted: 07-Nov-2008 at 2:44pm

We have a WPF window that allows modifying a Customer and also contains a ListView to display Customer.Addresses via a WPF binding. 

When we add a new Address to a Customer, we do something like this:
newAddress.Customer = ourCustomer;
ourCustomer.Addresses_Reference.AddEntity(newAddress.EntityAspect.EntityKey);  // probably unnecessary
 
Although the ourCustomer.Addresses collection itself now contains the new address, it does not show up in the ListView. The binding is not triggered as the collection does not seem to be bindable: it does not implement the INotifyCollectionChanged interface required for WPF bindings.
 
Question : how does one go about implementing such bindings without having to repeatedly move elements between  relation collections and externally declared EntityList<T>-s?
While this workaround might work for a relatively small application, an enterprise app. containing hundreds of dialogs would suffer painfully.
 
Thanks for any suggestions...
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 10-Nov-2008 at 4:15pm
Originally posted by allo

Question : how does one go about implementing such bindings without having to repeatedly move elements between  relation collections and externally declared EntityList<T>-s?

 
Navigation properties generated by the DevForce EF object Mapper are currently typed as IList<T>, although in fact what you are being returned is a RelatedEntityList<T>, and the returned list can be cast as such. In the future we may change these to return a RelatedEntityList<T> directly. (First we have to solve a problem or two that arises when related entity lists are returned in an anonymous type via a LINQ query.)
 
Whatever type we return when you reference a navigation collection property, it won't (at least by default) implement INotifyCollectionChanged, because that interface is defined in the WindowsBase assembly, which is all about WPF, which is, of course, all about the presentation layer of an application, not the business model. Microsoft has worked hard to keep these layers separate, and so have we. A developer building an application with a DevForce EF persistence layer and a WinForm user interface might well wonder why he needs a reference to an assembly designed for WPF support!
 
On the other hand, it is likely that whatever list we return will provide notification of changes in some form, possibly through implementation of IBindingList<T>.  That seems to provide the same notification functionality that INotifyCollectionChanged does, except that it has the advantage of being recognized by Winforms data binding as well as WPF data binding. See this discussion from Rocky Lhotka:
 
 
The best you can do meanwhile might be just to tell the control, when you update the list, to refresh itself. You can find discussions of that by googling "refresh wpf binding". E.g.,
 
 
Pretty sure we'll have a better solution for you in the next release.
 
Back to Top
allo View Drop Down
Newbie
Newbie
Avatar

Joined: 27-Oct-2008
Location: Toronto, ON
Posts: 7
Post Options Post Options   Quote allo Quote  Post ReplyReply Direct Link To This Post Posted: 11-Nov-2008 at 10:25am
Thanks Greg,
 
Would you happen to know an approximate time of this next release?


Edited by allo - 11-Nov-2008 at 10:26am
Back to Top
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Posted: 11-Nov-2008 at 1:47pm
We're meeting to discuss this on Thursday - I'll try to let you know something after that.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down