Account Options

  1. Sign in
The old Google Groups will be going away soon.
Switch to the new Google Groups.
Google Groups Home
« Groups Home
MVVM binding strategy poll
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  Messages 1 - 25 of 43 - Collapse all  -  Translate all to Translated (View all originals)   Newer >
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Paul Stovell  
View profile  
 More options Feb 6 2010, 5:25 am
From: Paul Stovell <p...@paulstovell.com>
Date: Sat, 6 Feb 2010 20:25:01 +1000
Local: Sat, Feb 6 2010 5:25 am
Subject: MVVM binding strategy poll

Hi Disciples,

I just wanted to do a quick poll about wiring up MVVM:

First, what do you use to connect the view and view models together?

1. DataContext
2. View-level resource (e.g., Window.Resources)
3. Application-level resource (Application.Resources)
4. ObjectDataProvider
5. Other?

Secondly, how do you create the view model?

1. In XAML as a resource
2. Creation in the view constructor
3. VM is injected into the view (e.g., as constructor parameter) - view sets
it as data context/resource
4. External code (e.g., App_Startup) creates the view and the VM and sets it
as data context/resource
5. A ServiceLocator pattern
6. Other?

Also interested in things you like and dislike about a particular approach.

--
Paul Stovell


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Stovell  
View profile  
 More options Feb 6 2010, 5:29 am
From: Paul Stovell <p...@paulstovell.com>
Date: Sat, 6 Feb 2010 20:29:42 +1000
Local: Sat, Feb 6 2010 5:29 am
Subject: Re: MVVM binding strategy poll

For me, it's always been DataContext (1) and either injecting the VM via IOC
(3) or through some centralized external code. That might look something
like this:

public void ShowView<TView, TViewModel>()
{
   var view = container.Resolve<TView>();
   var model = container.Resolve<TViewModel>();
   view.DataContext = model;
   ...

--
Paul Stovell

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Sync  
View profile  
 More options Feb 6 2010, 5:37 am
From: Michael Sync <mchls...@gmail.com>
Date: Sat, 6 Feb 2010 18:37:41 +0800
Local: Sat, Feb 6 2010 5:37 am
Subject: Re: [WPF Disciples] Re: MVVM binding strategy poll

>>Secondly, how do you create the view model?

Yeah. I'm also using ShowView<TV,TVM> like Paul's method in Module class.

If I'm not using IoC, I would create VM instance in XAML,

If we are using Singleton Container like Daniel's framework then we can
create a custom markup extension to resolve the VM in XAML.  I'm thinking
whether it's good idea or not.

>>Creation in the view constructor

Some people in my company used to do that thing. But I more prefer to set DC
from external code like ShowView().

Thanks and Best Regards,
Michael Sync

Don't go the way life takes you.
Take life the way you go

http://michaelsync.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter O'Hanlon  
View profile  
 More options Feb 6 2010, 8:11 am
From: "Peter O'Hanlon" <pete.ohan...@gmail.com>
Date: Sat, 6 Feb 2010 13:11:11 +0000
Local: Sat, Feb 6 2010 8:11 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

For concrete implementations, i.e. no IoC, I always define in the XAML as a
DataContext, e.g.:
<Window.Resources>
  <local:ConcreteViewModel x:Key="VM" />
</Window.Resources>
<Grid DataContext="{StaticResource VM}">

This is just the way I like to define things - it makes it obvious for the
designer where things are coming from.

--
Peter O'Hanlon

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Daniel Vaughan  
View profile  
 More options Feb 6 2010, 8:20 am
From: Daniel Vaughan <dbvaug...@gmail.com>
Date: Sat, 6 Feb 2010 05:20:07 -0800 (PST)
Local: Sat, Feb 6 2010 8:20 am
Subject: Re: MVVM binding strategy poll
That's how I do things too Pete. Maybe IOC could bring some further
extensibility, but I haven't seen the need for it so far.

On Feb 6, 2:11 pm, "Peter O'Hanlon" <pete.ohan...@gmail.com> wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Peter O'Hanlon  
View profile  
 More options Feb 6 2010, 8:23 am
From: "Peter O'Hanlon" <pete.ohan...@gmail.com>
Date: Sat, 6 Feb 2010 13:23:30 +0000
Local: Sat, Feb 6 2010 8:23 am
Subject: Re: [WPF Disciples] Re: MVVM binding strategy poll

We are of one mind - it's like some form of Vulcan Mind Meld.[?]

--
Peter O'Hanlon

  35C.png
< 1K Download

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Corrado Cavalli  
View profile  
 More options Feb 6 2010, 8:47 am
From: "Corrado Cavalli" <corradocava...@gmail.com>
Date: Sat, 6 Feb 2010 14:47:38 +0100
Local: Sat, Feb 6 2010 8:47 am
Subject: RE: [WPF Disciples] MVVM binding strategy poll

I'm using MVVM-Light's approach to bind DataContext to a property exposed by
a ViewModelLocator class instantiated as application wide resource.

.Corrado

From: wpf-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Paul Stovell
Sent: sabato 6 febbraio 2010 11:25
To: wpf-disciples@googlegroups.com
Subject: [WPF Disciples] MVVM binding strategy poll

Hi Disciples,

I just wanted to do a quick poll about wiring up MVVM:

First, what do you use to connect the view and view models together?

1. DataContext
2. View-level resource (e.g., Window.Resources)
3. Application-level resource (Application.Resources)
4. ObjectDataProvider
5. Other?

Secondly, how do you create the view model?

1. In XAML as a resource
2. Creation in the view constructor
3. VM is injected into the view (e.g., as constructor parameter) - view sets
it as data context/resource
4. External code (e.g., App_Startup) creates the view and the VM and sets it
as data context/resource
5. A ServiceLocator pattern
6. Other?

Also interested in things you like and dislike about a particular approach.

--
Paul Stovell


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Bill Kempf  
View profile  
 More options Feb 6 2010, 10:02 am
From: Bill Kempf <weke...@gmail.com>
Date: Sat, 6 Feb 2010 10:02:56 -0500
Local: Sat, Feb 6 2010 10:02 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

On Sat, Feb 6, 2010 at 5:25 AM, Paul Stovell <p...@paulstovell.com> wrote:
> Hi Disciples,

> I just wanted to do a quick poll about wiring up MVVM:

> First, what do you use to connect the view and view models together?

> 1. DataContext
> 2. View-level resource (e.g., Window.Resources)
> 3. Application-level resource (Application.Resources)
> 4. ObjectDataProvider
> 5. Other?

Today, Onyx uses a View first approach and connects the two via an
attached property (as well as sets the DataContext). I'm moving to
ViewModel first, and the attached property will still be used, but it
will be read only.

> Secondly, how do you create the view model?

> 1. In XAML as a resource
> 2. Creation in the view constructor
> 3. VM is injected into the view (e.g., as constructor parameter) - view sets
> it as data context/resource
> 4. External code (e.g., App_Startup) creates the view and the VM and sets it
> as data context/resource
> 5. A ServiceLocator pattern
> 6. Other?

Today in Onyx if you set View.Model to a Type, it's created during
coercion (using DI). Since I'm moving to VM first, it will be created
by a ViewModelActivator.

> Also interested in things you like and dislike about a particular approach.

> --
> Paul Stovell

--
 Quidquid latine dictum sit, altum sonatur.
- Whatever is said in Latin sounds profound.

War is peace. Freedom is slavery.  Bugs are features.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Laurent Bugnion  
View profile  
 More options Feb 6 2010, 12:53 pm
From: "Laurent Bugnion" <laur...@galasoft.ch>
Date: Sat, 6 Feb 2010 18:53:54 +0100
Local: Sat, Feb 6 2010 12:53 pm
Subject: RE: [WPF Disciples] MVVM binding strategy poll
Me too (obviously), unless this is a super simple demo app, in which case i do what Pete showed with the VM in the Window/UC's resources.

In the future i want to experiment a bit and make the ViewModelLocator a bit more like a factory.

Cheers,
Laurent
--
Sent from mobile

-original message-
Subject: RE: [WPF Disciples] MVVM binding strategy poll
From: "Corrado Cavalli" <corradocava...@gmail.com>
Date: 06.02.2010 14:48

I'm using MVVM-Light's approach to bind DataContext to a property exposed by
a ViewModelLocator class instantiated as application wide resource.

.Corrado

From: wpf-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Paul Stovell
Sent: sabato 6 febbraio 2010 11:25
To: wpf-disciples@googlegroups.com
Subject: [WPF Disciples] MVVM binding strategy poll

Hi Disciples,

I just wanted to do a quick poll about wiring up MVVM:

First, what do you use to connect the view and view models together?

1. DataContext
2. View-level resource (e.g., Window.Resources)
3. Application-level resource (Application.Resources)
4. ObjectDataProvider
5. Other?

Secondly, how do you create the view model?

1. In XAML as a resource
2. Creation in the view constructor
3. VM is injected into the view (e.g., as constructor parameter) - view sets
it as data context/resource
4. External code (e.g., App_Startup) creates the view and the VM and sets it
as data context/resource
5. A ServiceLocator pattern
6. Other?

Also interested in things you like and dislike about a particular approach.

--
Paul Stovell


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Josh Smith  
View profile  
 More options Feb 6 2010, 1:14 pm
From: Josh Smith <flappleja...@gmail.com>
Date: Sat, 6 Feb 2010 10:14:14 -0800
Local: Sat, Feb 6 2010 1:14 pm
Subject: Re: [WPF Disciples] MVVM binding strategy poll

I put it in XAML as DataContext if the application architecture allows for
it (i.e. no need for the VM's ctor to take parameters).  Often I find that
VM's are created in code, based on runtime context, and added to the logical
tree as a forcing function for a View to be created via typed DataTemplates.

Josh


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glenn Block  
View profile  
 More options Feb 6 2010, 2:55 pm
From: Glenn Block <glenn.bl...@gmail.com>
Date: Sat, 6 Feb 2010 11:55:30 -0800
Local: Sat, Feb 6 2010 2:55 pm
Subject: Re: [WPF Disciples] MVVM binding strategy poll

In general I ues on of the following

1. Inject the VM into the View (through an IOC) and set the DC.
2. Use a service which gets the VM and sets the DC.
3. Use an attached property which does the marriage.

When I was on the Prism team we favored more of a VM->First approach where
the VM gets the view injected into it, and then immediately sets a "Model"
property on the view that was injected, which sets the DC.

Lately I find I am favoring 1 and 3 over 2.

Glenn


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glenn Block  
View profile  
 More options Feb 6 2010, 2:58 pm
From: Glenn Block <glenn.bl...@gmail.com>
Date: Sat, 6 Feb 2010 11:58:17 -0800
Local: Sat, Feb 6 2010 2:58 pm
Subject: Re: [WPF Disciples] MVVM binding strategy poll

I should add I do like using Jonas' locator in resources method for the
blendability benefits. However, outside of that it's not the way I would
prefer to go as it adds complexity for the sake of designability. If I could
have my cake and eat it too, then VM location would just be a first class
member in SL/WPF/Cider/Blend. I would optimally not have to decorate the
View / call any imperative code to get the wire-up to happen...it would just
"happen". I'll keep dreaming of the day when this is possible.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glenn Block  
View profile  
 More options Feb 6 2010, 3:01 pm
From: Glenn Block <glenn.bl...@gmail.com>
Date: Sat, 6 Feb 2010 12:01:01 -0800
Local: Sat, Feb 6 2010 3:01 pm
Subject: Re: [WPF Disciples] MVVM binding strategy poll

Forgot to mention, the reason I no longer prefer the approach of having the
View created as part of injection during the VM creation is because it
forces you to dynamically compose your entire UI rather than letting the
XAML parser do it for you...hence why you end up having regions in regions
in regions.

Glenn


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Paul Stovell  
View profile  
 More options Feb 7 2010, 4:01 am
From: Paul Stovell <p...@paulstovell.com>
Date: Sun, 7 Feb 2010 19:01:29 +1000
Local: Sun, Feb 7 2010 4:01 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

Hi Glenn,

>> where the VM gets the view injected into it, and then immediately sets a

"Model" property on the view that was injected

So something like:

public EditCustomerViewModel(IEditCustomerView view)
{
    view.Model = this; // ?

}

This seems more like Model View Presenter to me?

Paul

--
Paul Stovell

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Sync  
View profile  
 More options Feb 7 2010, 8:30 am
From: Michael Sync <mchls...@gmail.com>
Date: Sun, 7 Feb 2010 21:30:11 +0800
Local: Sun, Feb 7 2010 8:30 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

Hi Glenn,

I agreed with Paul.

>>hence why you end up having regions in regions in regions.

Maybe, I'm so dumb. I can understand more clearly when I see the code
example. Could you please provide the sample? IsShowPopup property of View
and updating the view after closing popup can be achieved without having an
interface of View in ViewModel...

Thanks and Best Regards,
Michael Sync

Don't go the way life takes you.
Take life the way you go

http://michaelsync.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glenn Block  
View profile  
 More options Feb 7 2010, 9:46 am
From: Glenn Block <glenn.bl...@gmail.com>
Date: Sun, 7 Feb 2010 06:46:31 -0800
Local: Sun, Feb 7 2010 9:46 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll
Hi Paul

I am saying this is 'not' the approach I prefer any longer, but the
one we used in p&p. It is closer to MVP style in terms of hookup.
Setting the model property sets the DC on the view.

The approach I prefer is having the VM and View married (through a
service) or having the VM injected in to the view.

Michael, that's a different thread :-)

On 2/7/10, Paul Stovell <p...@paulstovell.com> wrote:

--
Sent from my mobile device

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glenn Block  
View profile  
 More options Feb 7 2010, 9:50 am
From: Glenn Block <glenn.bl...@gmail.com>
Date: Sun, 7 Feb 2010 06:50:01 -0800
Local: Sun, Feb 7 2010 9:50 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll
As far as whether it is MVP or not, as I mentioned I believe the key
differentiator is that with MVVM the view is directly bound to the
ViewModel and talks to the VM through databinding. In MVP, the view is
bound to a model hanging off the SupervisingController or not bound at
all (passive view).

So whether or not the VM has a reference to the View does not
determine it's VMNess......

My $.02

On 2/7/10, Paul Stovell <p...@paulstovell.com> wrote:

--
Sent from my mobile device

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Sync  
View profile  
 More options Feb 7 2010, 10:08 am
From: Michael Sync <mchls...@gmail.com>
Date: Sun, 7 Feb 2010 23:08:29 +0800
Local: Sun, Feb 7 2010 10:08 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

>>Michael, that's a different thread :-)

:) yeah. Sorry. :)

>>I believe the key differentiator is that with MVVM the view is directly

bound to the ViewModel and talks to the VM through databinding.

View talks to VM thought databinding in MVVM. Okay. Great. Thanks.

How does ViewModel talk to View? How does Presenter talk to View?

Thanks and Best Regards,
Michael Sync

Don't go the way life takes you.
Take life the way you go

http://michaelsync.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glenn Block  
View profile  
 More options Feb 7 2010, 10:29 am
From: Glenn Block <glenn.bl...@gmail.com>
Date: Sun, 7 Feb 2010 07:29:35 -0800
Local: Sun, Feb 7 2010 10:29 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

I think it depends.

I can think of 6 approaches all of which have pros and cons

 1. INPC / Property binding
2. Events
3. Messages (Event Aggregator/Messenger/RX framework)
4. Through an intermediary such as a service
5. Through an interface
6. Through delegates (View passes delegates to the VM which it can use to
call it back. For example VM might expose a SetActions method which the View
calls passing it delegates.

In the MVP case the standard is the Presenter talks back to the view either
through an interface, databinding, or through properties in the case of
Passive view. With Passive View the properties are not using databinding,
instead the view property getters and setters are used to directly set the
control value.

Glenn


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Sync  
View profile  
 More options Feb 7 2010, 10:57 am
From: Michael Sync <mchls...@gmail.com>
Date: Sun, 7 Feb 2010 23:57:38 +0800
Local: Sun, Feb 7 2010 10:57 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

Hi Glenn,

Thanks a lot. Glenn. This is very interesting..

Let me think about some scenarios for 6 approaches. I will also listen what
other will say about this.. I'm sending some emails to other people who are
using MVVM and putting some discussions in a few forums as well. I will
discuss with you about the sample and real scenarios for 6 approaches
later.. If everyone agree with that then it's cool..

Thanks and Best Regards,
Michael Sync

Don't go the way life takes you.
Take life the way you go

http://michaelsync.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glenn Block  
View profile  
 More options Feb 7 2010, 11:01 am
From: Glenn Block <glenn.bl...@gmail.com>
Date: Sun, 7 Feb 2010 08:01:21 -0800
Local: Sun, Feb 7 2010 11:01 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

I am working on a blog post on this as we speak (write)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Sync  
View profile  
 More options Feb 7 2010, 11:02 am
From: Michael Sync <mchls...@gmail.com>
Date: Mon, 8 Feb 2010 00:02:21 +0800
Local: Sun, Feb 7 2010 11:02 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

Hi Glenn,

Great.. Thanks, Glenn. I'm looking forward to read your post. Thanks.

Thanks and Best Regards,
Michael Sync

Don't go the way life takes you.
Take life the way you go

http://michaelsync.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glenn Block  
View profile  
 More options Feb 7 2010, 11:02 am
From: Glenn Block <glenn.bl...@gmail.com>
Date: Sun, 7 Feb 2010 08:02:35 -0800
Local: Sun, Feb 7 2010 11:02 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

I think there's a lot of overlap and at the end of the day it comes down to
preference. The big delineation is can it be handled through binding or not?
In the case of "not" there are a range options (the 5)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Michael Sync  
View profile  
 More options Feb 7 2010, 11:09 am
From: Michael Sync <mchls...@gmail.com>
Date: Mon, 8 Feb 2010 00:09:27 +0800
Local: Sun, Feb 7 2010 11:09 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

Hi Glenn,

>> In the case of "not" there are a range options (the 5)

Yeah. But I'm wondering if there is any other way like using DP or attached
property instead of having an interface of View in ViewModel. I think I need
to take some times to understand the need. It would be really great if you
can add some real scenarios (and also samples) for 6 approaches (esp: 2, 5,
6 ) in your blog post.

Thanks a lot, Glenn.

Thanks and Best Regards,
Michael Sync

Don't go the way life takes you.
Take life the way you go

http://michaelsync.net


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Glenn Block  
View profile  
 More options Feb 7 2010, 11:19 am
From: Glenn Block <glenn.bl...@gmail.com>
Date: Sun, 7 Feb 2010 08:19:58 -0800
Local: Sun, Feb 7 2010 11:19 am
Subject: Re: [WPF Disciples] MVVM binding strategy poll

When you say DPs, are you mean the VM inherits from DependencyObject? Or are
you saying the VM gets DPs passed into it that it uses to talk back?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Messages 1 - 25 of 43   Newer >
« Back to Discussions « Newer topic     Older topic »