I’m using MVVM-Light’s approach to bind DataContext to a property exposed by a ViewModelLocator class instantiated as application wide resource.
.Corrado
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.
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" <corrado...@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-di...@googlegroups.com [mailto:wpf-di...@googlegroups.com]
On Behalf Of Paul Stovell
Sent: sabato 6 febbraio 2010 11:25
To: wpf-di...@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
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 :-)
--
Sent from my mobile device
So whether or not the VM has a reference to the View does not
determine it's VMNess......
My $.02
--
That included a nice long discussion with Ward and a few Laurent interruptions.
Blog post pedning....
On 2/7/10, Jeremiah Morrill <jeremiah...@gmail.com> wrote:
> Why'd you guys stop! This is pretty good stuff :)!
>
> I'll say that I practice *M-V-PVM (*Dunno what we are calling it). There is
> an overall attempt to do do things with first with binding, behaviors,
> commands, and this covers *most* of my needs...but if I have to jump through
> hoops (like making non-reusable or over complicated solutions) to stay pure,
> communication via interfaces is my general fallback. When I'm opening up my
> IV/IVM interfaces, my biggest concern with view-code-behind is, how
> blendable is it? Does it hide or complicate a designer's ability to use it?
>
> We can solve a lot with Blend behaviors, mediators and maybe custom
> controls, but relying on all for everything, I imagine, could
> have maintenance pains. Just imagine a Blend designer being faced with
> hundreds of behaviors in their pallet. Or a developer having to
> managed mountains of "mediator message" definitions. (I suppose you could
> say the same thing about having mountains of interfaces) Sometimes opening
> up an interface is just a *good *solution to a simple problem.
>>> *View*
I'll go back to Onyx again. We'll stick with the current Onyx design,
so that you can see things in action. We'll start with something
simple: being able to display a message. The designer doesn'tpe do a
thing. The developer uses the View.Activated event to register an
IDisplayMessage with the view. In fact, the framework does this for
you if you want the default behavior of displaying a message box, and
you'll only need to register a different service implementation if you
want to change that behavior. This can be done based on the Type of
the view. The ViewModel then uses the IView (which inherits
IServiceProvider) to obtain the IDisplayMessage service. The ViewModel
is entirely decoupled from any specific view, and remains testable,
while the designer's workflow wasn't impacted and he need not write a
line of code.
In Onyx V2, things remain very similar, but the IDisplayMessage will
be injected via the ViewModel's constructor instead of using Service
Location. This means that IView will no longer be an IServiceProvider,
and instead this service exists solely to deal with
Show/ShowModal/Close operations, which are important when going with a
ViewModel first design.
--
Quidquid latine dictum sit, altum sonatur.
- Whatever is said in Latin sounds profound.
War is peace. Freedom is slavery. Bugs are features.