Implementing IViewFor<T>

76 views
Skip to first unread message

James Nugent

unread,
May 20, 2013, 8:33:26 AM5/20/13
to reacti...@googlegroups.com
Hi,

Is there a reason *not* to implement IViewFor<T> like this:

object IViewFor.ViewModel
    get { return DataContext; }
    set { DataContext = value; }

public MainWindowViewModel ViewModel
{
    get { return (MainWindowViewModel) DataContext; }
    set { DataContext = value; }
}

Obviously I realise that it's possible to use any dependency property here, but just wondering if there are any disadvantages to the above approach that aren't immediately obvious here?

Thanks,


James

Paul Betts

unread,
May 20, 2013, 12:07:23 PM5/20/13
to ReactiveUI mailing list
You probably don't want to do this, I'd be surprised if Bind or OneWayBind would work here at all, especially if you changed the ViewModel, due to the way that WhenAny works (which Bind and OneWayBind use internally). If an object is a DependencyObject, we expect that we can find a static "[NameOfProperty]Property" field along with it.


--
You received this message because you are subscribed to the Google Groups "ReactiveUI mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to reactivexaml...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

James Nugent

unread,
May 21, 2013, 1:19:43 PM5/21/13
to reacti...@googlegroups.com
You're right, this only works in trivial cases. Bind and OneWayBind both work but fail when the ViewModel instance is switched out.

Thanks,


James
Reply all
Reply to author
Forward
0 new messages