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 Questions
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 54 - 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
 
Michael Sync  
View profile  
 More options Feb 3 2010, 11:38 am
From: Michael Sync <mchls...@gmail.com>
Date: Thu, 4 Feb 2010 00:38:26 +0800
Local: Wed, Feb 3 2010 11:38 am
Subject: Re: MVVM Questions

Thanks a lot, John. I'm really appreciate it.

What about if you and our WPF/Silverlight community create a standard for
MVVM pattern? I understand that there are a lot of way to implement MVVM but
at least, there are some obvious rules that everyone can follow so everyone
has same understanding about that pattern.

Here are some of my thoughts.

*Goals*

   -
   - Testabiltiy ( ViewModel is easier to unit test than code-behind or
   event driven code)
   - Clear seperation between UX designer and developer
   - Increases the "Blendability" of your view
   - Model never needs to be changed to support changes to the view
   - ViewModel rarely needs to be changed to support changes to the view
   - No duplicated code to update views

*Do and Don't in View*

   - *shouldn't contain any logic that you want to test* : As Glenn said
   that MVVM is not code counting exercise, we can write code in code-behind.
   But you should never write any logic that you want to test. For example: If
   user select a country then you want to display the list of states or city in
   your view. This is the business requirement so you should have unit test to
   test this logic. So, you shouldn't write it in code-behind.
   - *can be a user control or Data Template*
   - *Keep the view as simple as possible. : *We can still use Data Trigger
   or Value Converter or Visual State or Blend Behivor in XAML with care.
   - *use attached property if something is not bindable : *There is one
   common mistake about PasswordBox. We all knows that WPF Password is not
   bindable due to the security reason. But if you are having a string property
   "Password" in Model then it won't be secure no matter whether you set it
   from code-behind or attached property.

*Do and Don't in ViewModel*

   - An abstraction of View
   - Connector between View and Model
   - Keep View State, Value Conversion
   - No strong or weak (via Interface) reference of View
   - Make VM as testable as possible (e.g. no call to Singleton class)
   - No Control related Stuff in VM ( Because if you are changing the view
   then you will have to change VM as well. )

*Model *

   -
   - can be Data Model, DTO, POCO, auto-generated proxy of domain class and
   UI Model based on how you want to have the separation between Domain Service
   and Presentation Layer
   - No reference to 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.
Bill Kempf  
View profile  
 More options Feb 3 2010, 12:15 pm
From: Bill Kempf <weke...@gmail.com>
Date: Wed, 3 Feb 2010 12:15:19 -0500
Local: Wed, Feb 3 2010 12:15 pm
Subject: Re: [WPF Disciples] Re: MVVM Questions

On Wed, Feb 3, 2010 at 11:38 AM, Michael Sync <mchls...@gmail.com> wrote:
> Do and Don't in View

> shouldn't contain any logic that you want to test : As Glenn said that MVVM
> is not code counting exercise, we can write code in code-behind. But you
> should never write any logic that you want to test. For example: If user
> select a country then you want to display the list of states or city in your
> view. This is the business requirement so you should have unit test to test
> this logic. So, you shouldn't write it in code-behind.

This is a wonderful description of the requirement. Fully on board.
From a personal POV, I like to go a little further, not for a
developer/architectural reason, but because I want the View to be as
nearly entirely in the realm of the designer as possible, and the
designer shouldn't be writing code. But that's not really a
goal/requirement of MVVM.

> can be a user control or Data Template

Or custom control ;). Sorry, I know you meant this, but saying "user
control" instead of just "control" rubbed me wrong.

> Keep the view as simple as possible. : We can still use Data Trigger or
> Value Converter or Visual State or Blend Behivor in XAML with care.

I'm not sure I understand this. It doesn't seem to be related to MVVM
and I don't know what you mean by "with care".

> use attached property if something is not bindable : There is one common
> mistake about PasswordBox. We all knows that WPF Password is not bindable
> due to the security reason. But if you are having a string property
> "Password" in Model then it won't be secure no matter whether you set it
> from code-behind or attached property.

This seems like an implementation detail and not a goal/requirement.
Also, while I don't really understand why PasswordBox's design makes
it "secure", I can't agree that having a property in the Model makes
anything insecure. Your model could just as easily use a SecureString
making it "secure". Then all that's in question is how you move the
password from the PasswordBox to the Model in a secure fashion, and
that can certainly be accomplished in various ways, such as using a
service. Heck, it could probably even be done using the attached
behavior approach. I'd suggest you drop this from the list.

> Do and Don't in ViewModel

> An abstraction of View

That's the definition of the pattern, right? Not sure you need to call
it out in a do/don't list.

> Connector between View and Model

Possible between View and Models.

> Keep View State, Value Conversion

Value conversion need not go in the ViewModel, so you should be
careful in how this is worded.

> No strong or weak (via Interface) reference of View

I simply can't agree with this. At all. There's no benefit in forcing
this, and in fact there's a lot of benefits in maintaining a "weak
reference" (wrong term, but it's what you used) to the View.

> Make VM as testable as possible (e.g. no call to Singleton class)

The Singleton pattern must die! If for no other reason than the
confusion it brings to discussions like this. IoC containers have the
concept of a singleton, but they are obtained through dependency
injection instead of through calls to static methods. That's what you
really meant by Singleton here, is you shouldn't have a dependency on
static methods/properties.

> No Control related Stuff in VM ( Because if you are changing the view then
> you will have to change VM as well. )

Depends on what you mean by "control related". You absolutely should
not have any hard dependencies on a control, but looser dependencies
may be necessary. For instance, being able to change the focus may be
a necessary part of the "business logic" of the View, and you'll need
to be able to do that in the ViewModel. There's ways to do this in an
abstract fashion that does not create hard dependencies between the
ViewModel and any particular View. This is fine. Kind of like with the
"no reference to the View" item above, it's really only important that
you need create hard dependencies.

> Model

> can be Data Model, DTO, POCO, auto-generated proxy of domain class and UI
> Model based on how you want to have the separation between Domain Service
> and Presentation Layer
> No reference to ViewModel

--
 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.
Michael Sync  
View profile  
 More options Feb 3 2010, 12:55 pm
From: Michael Sync <mchls...@gmail.com>
Date: Thu, 4 Feb 2010 01:55:20 +0800
Local: Wed, Feb 3 2010 12:55 pm
Subject: Re: [WPF Disciples] Re: MVVM Questions

Thanks, Bill.

>> that's not really a goal/requirement of MVVM.

Testability is one of the goals of MVVM, right? So, having business logic in
View is not good idea. So, I was suggesting that we should not put any logic
that we want to test in codebehind.

>>control" instead of just "control" rubbed me wrong.

Yeah. Thanks. :)

>>I'm not sure I understand this. It doesn't seem to be related to MVVM and

I don't know what you mean by "with care".

We used to argue that using Data Trigger in View is not good idea because it
allows us to write the logic in View.

>>I'm not sure I understand this. It doesn't seem to be related to MVVM
>>Value conversion need not go in the ViewModel, so you should be careful in

how this is worded.

Im refering Justin's Value Converter Code smell. Let's say you want to show
the Country Name. But you have only Country ID in VM so you will use VC to
converter ID to Name. The suggestion is that if we like to show the name
then just add it in VM instead of using Converter.

>>>while I don't really understand why PasswordBox's design makes it

"secure"

According to WPF team, they don't make Passwod bindable for Security. There
are a few discussion about that in WPF forum.

>> I can't agree that having a property in the Model makes anything insecure

Some people think that using attached property for Password is insecure and
they think that you should set it in codebehind. My point is that it doesn't
matter whether you use the attached property to bind the model or set it
manually from codebehind. As long as the property of Password is a string
then it will not be secure anyway.

Yes. You are right. We should use SecureString in Model and we can even use
SecureString in attached property. yeah.. It should not be in the list.

>>> Not sure you need to callit out in a do/don't list.

Yes. Agreed.

>>I simply can't agree with this. At all. There's no benefit in

forcing this, and

>>in fact there's a lot of benefits in maintaining a "weak reference" (wrong

term, but it's what you used) to the View.

I dont think it's wrong term. What I meant by "weak" is not .NET
WeakReference. I saw people using it like that in forum. Anyway, I'm not a
native English speaker so you can suggest me what I should call that one.

Could you please give me some example of having IVew in VM? Would it be like
MVP pattern?

Thanks for your inputs. I really appreciate it... I think that it will help
us to understand more about MVVM and we can have same understanding as
well.. Otherwise, people will say that My "MVVM" is totally different from
your MVVM.. :)

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.
Bill Kempf  
View profile  
 More options Feb 3 2010, 1:29 pm
From: Bill Kempf <weke...@gmail.com>
Date: Wed, 3 Feb 2010 13:29:37 -0500
Local: Wed, Feb 3 2010 1:29 pm
Subject: Re: [WPF Disciples] Re: MVVM Questions

On Wed, Feb 3, 2010 at 12:55 PM, Michael Sync <mchls...@gmail.com> wrote:
> Thanks, Bill.
>>> that's not really a goal/requirement of MVVM.
> Testability is one of the goals of MVVM, right? So, having business logic in
> View is not good idea. So, I was suggesting that we should not put any logic
> that we want to test in codebehind.

That's taken out of context, and you misunderstood me. "That's not
really a goal/requirement of MVVM" wasn't in reference to your stated
goal, but to my extended goal of eliminating code behind for the sake
of less designer friction.

>>>I'm not sure I understand this. It doesn't seem to be related to MVVM and
>>> I don't know what you mean by "with care".
> We used to argue that using Data Trigger in View is not good idea because it
> allows us to write the logic in View.

That sort of argument always bothers me. When something "allows you"
to do something, it's not the same as requiring or even encouraging
you to do it. The bad idea is putting business logic in the View, and
I can write plenty of data triggers that don't do that.

>>>I'm not sure I understand this. It doesn't seem to be related to MVVM
>>>Value conversion need not go in the ViewModel, so you should be careful in
>>> how this is worded.
> Im refering Justin's Value Converter Code smell. Let's say you want to show
> the Country Name. But you have only Country ID in VM so you will use VC to
> converter ID to Name. The suggestion is that if we like to show the name
> then just add it in VM instead of using Converter.

Yeah, and that idea is controversial. Me, I'd rather use a converter
if this is going to be done frequently. Does a much better job of
keeping things DRY this way. More importantly, there's a lot of value
converters that simply do NOT belong in the ViewModel, ever. Things
like a SeverityToColorConverter come to mind. This is solely a
presentation concept, and has no place in a ViewModel.

>>>I simply can't agree with this. At all. There's no benefit in
>>> forcing this, and
>>>in fact there's a lot of benefits in maintaining a "weak reference" (wrong
>>> term, but it's what you used) to the View.
> I dont think it's wrong term. What I meant by "weak" is not .NET
> WeakReference. I saw people using it like that in forum. Anyway, I'm not a
> native English speaker so you can suggest me what I should call that one.

Abstract is probably better than weak. And coupling is better than
reference. They mean the same thing in some contexts, but in .NET
languages a reference has a specific meaning, so "weak reference" can
confuse people.

> Could you please give me some example of having IVew in VM? Would it be like
> MVP pattern?

Onyx is heavily based on an IView concept, so you could look there. At
runtime, there's a logical coupling betwen a View and a ViewModel, and
not maintaining a physical reference between them can thus lead to
complications. For instance, if you take a ViewModel first approach,
you have to be careful to maintain a reference to the View somehow,
lest the GC collect the View prematurely.

> Thanks for your inputs. I really appreciate it... I think that it will help
> us to understand more about MVVM and we can have same understanding as
> well.. Otherwise, people will say that My "MVVM" is totally different from
> your MVVM.. :)

To some extent, that's a good thing. MVVM is a pattern. Patterns can
be applied in multiple ways. As long as the pattern is still adhered
to, the differing applications are not really relevant. Things like
"not having any reference to the View from the ViewModel" are not part
of the pattern.

--
 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.
Michael Sync  
View profile  
 More options Feb 3 2010, 9:51 pm
From: Michael Sync <mchls...@gmail.com>
Date: Thu, 4 Feb 2010 10:51:46 +0800
Local: Wed, Feb 3 2010 9:51 pm
Subject: Re: [WPF Disciples] Re: MVVM Questions

Hi Bill,

Good Morning!

Sorry for late reply.

>>Abstract is probably better than weak. And coupling is better

than reference. They mean the same thing in some contexts, but in
.NET languages a reference has a specific meaning, so "weak reference"
can confuse people.

Thanks, Bill. I will use "Abstract Coupling" instead of "Weak reference (via
interface)" in future.

>>Things like a SeverityToColorConverter come to mind. This is solely

a presentation concept, and has no place in a ViewModel.

Yeah. I totally agreed with this.

>>I can write plenty of data triggers that don't do that

That's why I wanted to say that we can use Data Triggers or Value Converter
in View. But we need to be careful not to write the business logic with Data
Trigger. Yes. I have seen that people use Data Trigger for
some business logic.

>>Onyx is heavily based on an IView concept, so you could look there

Sure. I'm planning to take a look at all MVVM frameworks.

Please help me to take a look at the code below. Is it MVP or MVVM?

interface IView{

  void ShowMessage(string message);

}

class View : IView {
    public void ShowMessage(string message){
              MessageBox.Show(this, message);
    }

}

class ViewModel{

private IView view;

public ViewModel(IVew view){

  this.view = view;

}

........

view.ShowMessage("This is a msg");

}
>>>To some extent, that's a good thing. MVVM is a pattern. Patterns can be

applied in multiple ways. As long as the pattern is still adhered to, the
differing applications are not really relevant. Things like "not having any
reference to the View from the ViewModel" are not part of the pattern.

This is what you believe, right? There are a lot of people who believe that
VM should not have any view reference. According to John's class diagram <
link <http://blogs.msdn.com/johngossman/archive/2006/04/13/576163.aspx>>,
the 2-ways binding is the only way that we communicate between View and
ViewModel. Not via interface.

I believe that "not having any reference to the View from the ViewModel" can
be a part of pattern because we don't want VM to be changed to support the
changes of View.

Actually, pattern has a name. The way of implementing the pattern can be
different and we can combine a few patterns together based on our need. But
still it has a name.

Regards,
Michael Sync

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.
Bill Kempf  
View profile  
 More options Feb 4 2010, 9:24 am
From: Bill Kempf <weke...@gmail.com>
Date: Thu, 4 Feb 2010 09:24:56 -0500
Local: Thurs, Feb 4 2010 9:24 am
Subject: Re: [WPF Disciples] Re: MVVM Questions

There's not enough info here to say for sure. It could go either way.
I will say, however, that this is not what I would do. Onyx has an
IDisplayMessage service for this.

>>>>To some extent, that's a good thing. MVVM is a pattern. Patterns can be
>>>> applied in multiple ways. As long as the pattern is still adhered to, the
>>>> differing applications are not really relevant. Things like "not having any
>>>> reference to the View from the ViewModel" are not part of the pattern.
> This is what you believe, right? There are a lot of people who believe that
> VM should not have any view reference. According to John's class diagram
> <link>, the 2-ways binding is the only way that we communicate between View
> and ViewModel. Not via interface.

I don't believe John intended the diagram to explicitly disallow other
forms of communication. For instance, it's readily accepted by most
that EventAggregator is a key part of MVVM, and that certainly allows
for other forms of communication. Regardless, yes, it's my very strong
opinion that there's nothing in the pattern that disallows services,
including a View service, and in fact there are many things that are
difficult to do at, at best, without this.

> I believe that "not having any reference to the View from the ViewModel" can
> be a part of pattern because we don't want VM to be changed to support the
> changes of View.

It's my contention that you don't need to change the ViewModel to
support the View even when using loose coupling.

> Actually, pattern has a name. The way of implementing the pattern can be
> different and we can combine a few patterns together based on our need. But
> still it has a name.

Not just a name, but a definition, and I contend that the definition
doesn't, nor should it, include an exclusion to the use of a view
service.

--
 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.
Shawn Wildermuth  
View profile  
 More options Feb 4 2010, 9:48 am
From: "Shawn Wildermuth" <shawn.li...@agilitrain.com>
Date: Thu, 4 Feb 2010 09:48:31 -0500
Local: Thurs, Feb 4 2010 9:48 am
Subject: RE: [WPF Disciples] Re: MVVM Questions
Both these options seems to like more coupling to me.  I am doing this via a
Message (usually handled by the Shell or some other service) to show
messages.  That way when in test or minimal dev environments, the message
can be sent, but ignored.

Thanks,
Shawn Wildermuth
http://wildermuth.com

Note: This was typed on a big ole laptop so any misspellings and
punctuations are completely my fault…not my phone’s.


 
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.
Sacha Barber  
View profile  
 More options Feb 4 2010, 9:57 am
From: Sacha Barber <sacha.bar...@gmail.com>
Date: Thu, 4 Feb 2010 14:57:10 +0000
Local: Thurs, Feb 4 2010 9:57 am
Subject: Re: [WPF Disciples] Re: MVVM Questions

I would say that is MVP, and I too would do that with a dedicated service,
that also has mocks that are DId in in my test cases.

On Thu, Feb 4, 2010 at 2:48 PM, Shawn Wildermuth <shawn.li...@agilitrain.com

--
Sacha Barber
sacha.bar...@gmail.com

 
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 4 2010, 10:03 am
From: Bill Kempf <weke...@gmail.com>
Date: Thu, 4 Feb 2010 10:03:06 -0500
Local: Thurs, Feb 4 2010 10:03 am
Subject: Re: [WPF Disciples] Re: MVVM Questions
Using a service, when in test or minimal dev environments, the service
method can be called, but ignored. You gain nothing by using a
Message, and some things can be complicated to accomplish using
methods.

On Thu, Feb 4, 2010 at 9:48 AM, Shawn Wildermuth

--
 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.
Sacha Barber  
View profile  
 More options Feb 4 2010, 10:21 am
From: Sacha Barber <sacha.bar...@gmail.com>
Date: Thu, 4 Feb 2010 15:21:37 +0000
Local: Thurs, Feb 4 2010 10:21 am
Subject: Re: [WPF Disciples] Re: MVVM Questions

Total agree with Bill here.

--
Sacha Barber
sacha.bar...@gmail.com

 
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 4 2010, 11:11 am
From: Michael Sync <mchls...@gmail.com>
Date: Fri, 5 Feb 2010 00:11:53 +0800
Local: Thurs, Feb 4 2010 11:11 am
Subject: Re: [WPF Disciples] Re: MVVM Questions

Thanks, Bill, Shawn and Sacha.

>>Onyx has an IDisplayMessage service for this.

We will probably call *IDisplayMessageService *in CAB,SCSF or Prism, In
MVVM, we used to have IDisplayMessageService or IDialogService or etc.

>>a View service

I think you mis-understand me. I'm not talking about IDisplayService or
ViewService. I just want to know whether *you have an interface for every
views* (like we have in MVP pattern) or not.

>>I would say that is MVP

Yes, Sacha. I raised the same question in other group as well. The most of
people believe that this is a MVP.

As of now, I think we have different thoughts about having the interface of
View in ViewModel. But good thing is that we all agree for all facts.

Please discuss if anyone like to add more on that..

Thanks for participating in discussion.. I really appreciate it. Actually,
I'm sharing some of my idea about MVVM pattern with my team and Singapore
Community. The most of people in my team have the working experience with
winform (CAB, SCSF and MVP pattern) so I used to get a lot of questions like
that.. there are only a few people who are using MVVM (even WPF or
Silverlight) so I don't get much people to discuss in SG. This group is the
only one that I can discuss online. Thanks again for your suggestion..  :)

Thanks and Best Regards,
Michael Sync

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

http://michaelsync.net

On Thu, Feb 4, 2010 at 11:21 PM, Sacha Barber <sacha.bar...@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.
Bill Kempf  
View profile  
 More options Feb 4 2010, 1:23 pm
From: Bill Kempf <weke...@gmail.com>
Date: Thu, 4 Feb 2010 13:23:16 -0500
Local: Thurs, Feb 4 2010 1:23 pm
Subject: Re: [WPF Disciples] Re: MVVM Questions

On Thu, Feb 4, 2010 at 11:11 AM, Michael Sync <mchls...@gmail.com> wrote:
> Thanks, Bill, Shawn and Sacha.

>>>Onyx has an IDisplayMessage service for this.

> We will probably call IDisplayMessageService in CAB,SCSF or Prism, In MVVM,
> we used to have IDisplayMessageService or IDialogService or etc.

Same concept, different name. It's a service whether you call it one
in the name or not.

>>>a View service

> I think you mis-understand me. I'm not talking about IDisplayService or
> ViewService. I just want to know whether you have an interface for every
> views (like we have in MVP pattern) or not.

Onyx has an IView for every view, yes. IView is a service.  It's main
purpose is to provide access to other services (it's an
IServiceProvider), but it does contain a property called ViewElement
that's the actual UIElement of the view. It's also probably going to
be gaining Show and Close methods in V2 of the framework. I've gone
back and forth on whether or not the ViewElement should be included,
because frankly anything you'd do with it could be accomplished with
out it using the IServiceProvider, but I have used it once or twice
for convenience (and in a manner that was testable and didn't couple
me to the specific view instance or implementation). I'll agree that
this is controversial, at best, but I'm pragmatic not dogmatic.

>>>I would say that is MVP

> Yes, Sacha. I raised the same question in other group as well. The most of
> people believe that this is a MVP.

Why? I don't think you can tell from what little was posted, but I'd
love to hear the reasoning.

--
 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.
Michael D. Brown  
View profile  
 More options Feb 4 2010, 1:22 pm
From: "Michael D. Brown" <mike.br...@azurecoding.net>
Date: Thu, 4 Feb 2010 13:22:53 -0500
Local: Thurs, Feb 4 2010 1:22 pm
Subject: RE: [WPF Disciples] Re: MVVM Questions

I agree with the good doctor on this. It doesn't matter if it's ViewModel or
Presenter it's all poo. In the strictest sense, a viewmodel shouldn't have a
reference to a given view.but that guidance is there because should you need
it a ViewModel can be reused with multiple views (you could even go so far
as having a ViewModel support multiple UI platforms such as WPF/Silverlight
and even ASP.NET MVC). If you don't need this capability, ignore that
guidance and put what you need into the VM. Just don't go hog wild and
consider using interfaces to remove coupling to a SPECIFIC view. Both of
these will open options for you in the future to support multiple views and
possible even different platforms.

From: wpf-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Michael Sync
Sent: Wednesday, February 03, 2010 9:52 PM
To: wpf-disciples@googlegroups.com
Subject: Re: [WPF Disciples] Re: MVVM Questions

interface IView{

  void ShowMessage(string message);

}

class View : IView {

    public void ShowMessage(string message){

              MessageBox.Show(this, message);

    }

}

class ViewModel{

private IView view;

public ViewModel(IVew view){

  this.view = view;

}

........

view.ShowMessage("This is a msg");

}
>>>To some extent, that's a good thing. MVVM is a pattern. Patterns can be

applied in multiple ways. As long as the pattern is still adhered to, the
differing applications are not really relevant. Things like "not having any
reference to the View from the ViewModel" are not part of the pattern.

This is what you believe, right? There are a lot of people who believe that
VM should not have any view reference. According to John's class diagram
<link <http://blogs.msdn.com/johngossman/archive/2006/04/13/576163.aspx> >,
the 2-ways binding is the only way that we communicate between View and
ViewModel. Not via interface.

I believe that "not having any reference to the View from the ViewModel" can
be a part of pattern because we don't want VM to be changed to support the
changes of View.

Actually, pattern has a name. The way of implementing the pattern can be
different and we can combine a few patterns together based on our need. But
still it has a name.


 
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 4 2010, 6:04 pm
From: Daniel Vaughan <dbvaug...@gmail.com>
Date: Thu, 4 Feb 2010 15:04:28 -0800 (PST)
Local: Thurs, Feb 4 2010 6:04 pm
Subject: Re: MVVM Questions
I try to avoid the ViewModel knowing about the view via an interface
if at all possible, preferring instead loosely coupled eventing (as in
Prisms). I see this a being 'pure' MVVM, and sometimes it may not be
practical.
I’d say that in non-arbitrary projects,  the message service is better
implemented as a service, as I think most of us do anyway.

On Feb 3, 5:38 pm, Michael Sync <mchls...@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.
Jeremiah Morrill  
View profile  
 More options Feb 4 2010, 6:29 pm
From: Jeremiah Morrill <jeremiah.morr...@gmail.com>
Date: Thu, 4 Feb 2010 15:29:25 -0800
Local: Thurs, Feb 4 2010 6:29 pm
Subject: Re: [WPF Disciples] Re: MVVM Questions

>>I try to avoid the ViewModel knowing about the view via an interface

if at all possible

+1 Daniel.  Though I try to avoid the *event aggregator* if the event needs
to be published from the View, like in the case of IActiveAware.  In that
scenario I might go into a cheaper/lazy MVP style by opening up the
IViewModel with an IViewModel.SetActive(...) and storing ref to IViewModel
on my IView.SetViewModel(...).


 
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.
Shawn Wildermuth  
View profile  
 More options Feb 4 2010, 6:43 pm
From: "Shawn Wildermuth" <shawn.li...@agilitrain.com>
Date: Thu, 4 Feb 2010 18:43:04 -0500
Local: Thurs, Feb 4 2010 6:43 pm
Subject: RE: [WPF Disciples] Re: MVVM Questions

Let me be clearer, I use commanding (or a  Behavior) to talk to the VM and
the VM can issue the message (a la the Messenger in MVVM Light, or
EventAggregator (which is growing too much trouble for me)).

Thanks,

Shawn Wildermuth

 <http://wildermuth.com/> http://wildermuth.com

Note: This was typed on a big ole laptop so any misspellings and
punctuations are completely my fault.not my phone's.

From: wpf-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Jeremiah Morrill
Sent: Thursday, February 04, 2010 6:29 PM
To: wpf-disciples@googlegroups.com
Subject: Re: [WPF Disciples] Re: MVVM Questions

>>I try to avoid the ViewModel knowing about the view via an interface

if at all possible

+1 Daniel.  Though I try to avoid the event aggregator if the event needs to
be published from the View, like in the case of IActiveAware.  In that
scenario I might go into a cheaper/lazy MVP style by opening up the
IViewModel with an IViewModel.SetActive(...) and storing ref to IViewModel
on my IView.SetViewModel(...).

On Thu, Feb 4, 2010 at 3:04 PM, Daniel Vaughan <dbvaug...@gmail.com> wrote:

I try to avoid the ViewModel knowing about the view via an interface
if at all possible, preferring instead loosely coupled eventing (as in
Prisms). I see this a being 'pure' MVVM, and sometimes it may not be
practical.
I'd say that in non-arbitrary projects,  the message service is better
implemented as a service, as I think most of us do anyway.

On Feb 3, 5:38 pm, Michael Sync <mchls...@gmail.com> wrote:

wrote:

<gossmans...@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.
Daniel Vaughan  
View profile  
 More options Feb 4 2010, 6:50 pm
From: Daniel Vaughan <dbvaug...@gmail.com>
Date: Thu, 4 Feb 2010 15:50:21 -0800 (PST)
Local: Thurs, Feb 4 2010 6:50 pm
Subject: Re: MVVM Questions
Jer, do you find the IViewModel.SetActive(...) approach to be useful
where a viewmodel oversees multiple views? I myself, generally go 1 to
1, but that’s just me. I would probably avoid having a means to set
the View using a base interface because it could be overused, but
again it’s a matter of preference.

On Feb 5, 12:29 am, Jeremiah Morrill <jeremiah.morr...@gmail.com>
wrote:

...

read more »


 
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 4 2010, 6:53 pm
From: Daniel Vaughan <dbvaug...@gmail.com>
Date: Thu, 4 Feb 2010 15:53:42 -0800 (PST)
Local: Thurs, Feb 4 2010 6:53 pm
Subject: Re: MVVM Questions
Yes, I forgot to mention commanding. Must be getting late. Cheers
Shawn.

On Feb 5, 12:43 am, "Shawn Wildermuth" <shawn.li...@agilitrain.com>
wrote:

...

read more »


 
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.
Jeremiah Morrill  
View profile  
 More options Feb 4 2010, 7:09 pm
From: Jeremiah Morrill <jeremiah.morr...@gmail.com>
Date: Thu, 4 Feb 2010 16:09:46 -0800
Local: Thurs, Feb 4 2010 7:09 pm
Subject: Re: [WPF Disciples] Re: MVVM Questions

Totally right..can be overused..which is a problem in it's own.  But for
special cases (like IActiveAware, which has to be implemented on your IView
class), I find it to be elegant.  So far, I've only had to mix up some MVP
and MVVM a few times.

In my code, the only thing that knows what an IView's concrete type is my
IoC container.  My typical IView looks like this:

public interface IView
{
     void SetViewModel(IViewModel viewModel)

}

and my IViewModel:

public interface IViewModel
{
    object View{get;}//read-only

}

and the concrete VM:

public class ViewModel : IViewModel
{
       public ViewModel(IView view)
       {
             view.SetViewModel(this);
             View = view;
       }

       public object View{get;private set;}

}

I would say 9/10 of my V/VM's look almost exactly like this (no extra
interface methods, interface properties) and one method.  The view never
storing the IViewModel beyond setting the DataContext.  But you see how this
method makes it ripe for mixing MVP...and ripe for abuse ;)

-Jer

...

read more »


 
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.
Shawn Wildermuth  
View profile  
 More options Feb 4 2010, 7:28 pm
From: "Shawn Wildermuth" <shawn.li...@agilitrain.com>
Date: Thu, 4 Feb 2010 19:28:23 -0500
Local: Thurs, Feb 4 2010 7:28 pm
Subject: RE: [WPF Disciples] Re: MVVM Questions

Curious, in your SetViewModel, you're specifying an interface.  Since I rely
heavily on binding, I just accept an object (since the bindings are
basically duck-typed).  What are you getting out of the interface?

Thanks,

Shawn Wildermuth

 <http://wildermuth.com/> http://wildermuth.com

Note: This was typed on a big ole laptop so any misspellings and
punctuations are completely my fault.not my phone's.

From: wpf-disciples@googlegroups.com [mailto:wpf-disciples@googlegroups.com]
On Behalf Of Jeremiah Morrill
Sent: Thursday, February 04, 2010 7:10 PM
To: wpf-disciples@googlegroups.com
Subject: Re: [WPF Disciples] Re: MVVM Questions

Totally right..can be overused..which is a problem in it's own.  But for
special cases (like IActiveAware, which has to be implemented on your IView
class), I find it to be elegant.  So far, I've only had to mix up some MVP
and MVVM a few times.

In my code, the only thing that knows what an IView's concrete type is my
IoC container.  My typical IView looks like this:

public interface IView

{

     void SetViewModel(IViewModel viewModel)

}

and my IViewModel:

public interface IViewModel

{

    object View{get;}//read-only

}

and the concrete VM:

public class ViewModel : IViewModel

{

       public ViewModel(IView view)

       {

             view.SetViewModel(this);

             View = view;

       }

       public object View{get;private set;}

}

I would say 9/10 of my V/VM's look almost exactly like this (no extra
interface methods, interface properties) and one method.  The view never
storing the IViewModel beyond setting the DataContext.  But you see how this
method makes it ripe for mixing MVP...and ripe for abuse ;)

-Jer

On Thu, Feb 4, 2010 at 3:50 PM, Daniel Vaughan <dbvaug...@gmail.com> wrote:

Jer, do you find the IViewModel.SetActive(...) approach to be useful
where a viewmodel oversees multiple views? I myself, generally go 1 to
1, but that's just me. I would probably avoid having a means to set
the View using a base interface because it could be overused, but
again it's a matter of preference.

On Feb 5, 12:29 am, Jeremiah Morrill <jeremiah.morr...@gmail.com>

wrote:

...

read more »


 
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 4 2010, 7:35 pm
From: Daniel Vaughan <dbvaug...@gmail.com>
Date: Thu, 4 Feb 2010 16:35:32 -0800 (PST)
Local: Thurs, Feb 4 2010 7:35 pm
Subject: Re: MVVM Questions
Another approach might be to make the View property setter on the
ViewModel base implementation internal, and set it using some factory
mechanism. Then the IActiveAware could be fulfilled without exposing
the ViewModel to subclasses. What do you think?

On Feb 5, 1:09 am, Jeremiah Morrill <jeremiah.morr...@gmail.com>
wrote:

...

read more »


 
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.
Jeremiah Morrill  
View profile  
 More options Feb 4 2010, 7:40 pm
From: Jeremiah Morrill <jeremiah.morr...@gmail.com>
Date: Thu, 4 Feb 2010 16:40:06 -0800
Local: Thurs, Feb 4 2010 7:40 pm
Subject: Re: [WPF Disciples] Re: MVVM Questions

I think for almost all usages, an object type would be fine in the
SetViewModel(...).  The only advantage I can see, beyond being ready for
some MVP *sloppiness, *is that on the VM ctor, when I run the
IView.SetViewModel(this), I get strong-typing on my one-to-one
view/viewmodel.  Maybe I just do it out of habit?  ;)

On Thu, Feb 4, 2010 at 4:28 PM, Shawn Wildermuth <shawn.li...@agilitrain.com

...

read more »


 
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.
Jeremiah Morrill  
View profile  
 More options Feb 4 2010, 8:00 pm
From: Jeremiah Morrill <jeremiah.morr...@gmail.com>
Date: Thu, 4 Feb 2010 17:00:45 -0800
Local: Thurs, Feb 4 2010 8:00 pm
Subject: Re: [WPF Disciples] Re: MVVM Questions

Daniel, I'm not sure I follow.  The IView (and VM) are both instantiated by
IoC.   IActiveAware is only used by the IRegionManager, but implemented on
your view.  I need to let the VM know when the RegionManager sets
IActiveAware.IsActive has changed.  So the way I understand my options are I
could use a message bus in code-behind, MVP style communication back to the
VM in code-behind, or inherit my IView from IActiveAware and hook into the
IsActiveChanged event from the VM (which I guess would be the same as MVP
style).

-Jer

...

read more »


 
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 5 2010, 3:03 am
From: Glenn Block <glenn.bl...@gmail.com>
Date: Fri, 5 Feb 2010 00:03:53 -0800
Local: Fri, Feb 5 2010 3:03 am
Subject: Re: [WPF Disciples] Re: MVVM Questions
I say it 'depends'

Yes you can send a message from the VM to the view. I would definitely
do this if there are multiple views of the same VM.

If however there is a 1 to 1 relationship between the View and VM
(which is very often the case) I say Yagni. It's much more
discoverable, intuitive and more clearly expresses intent to just have
an interface for the view. Then instead of sending a message, I just
directly invoke it.

I am sure several folks will disagree, so I am ready for you to
convince me otherwise :-)

On 2/4/10, Shawn Wildermuth <shawn.li...@agilitrain.com> wrote:

...

read more »


 
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 5 2010, 3:09 am
From: Glenn Block <glenn.bl...@gmail.com>
Date: Fri, 5 Feb 2010 00:09:03 -0800
Local: Fri, Feb 5 2010 3:09 am
Subject: Re: [WPF Disciples] Re: MVVM Questions
Where is that rule written that 'Thine ViewModel must not reference
thy view'? The pattern of MVVM (which is very similar to
PresentationModel) is all about the encapsulation of the View logic in
the model, and about the View talking to it through binding. It sets
no constraints on how the VM talks back to the biw.

On 2/4/10, Michael D. Brown <mike.br...@azurecoding.net> 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.
Messages 1 - 25 of 54   Newer >
« Back to Discussions « Newer topic     Older topic »