For this simple escenario using the derived property might be a better
option. I don't think going with a VM adds a lot of value here and the
Converter approach can get really messy when the number of converters grows
to an unmanegable degree.

The reason I'd suggest to do it in the View is that it's hard to then map
properties from your VM to your Model and you could end up with really
complex mappings or even with the requirement to have another layer
dedicated to this taks, thus making the pattern unecessarily complex.

For a simple view, might not seem like a big issue, but let's assume that
that object is part of a complex object hiarchy that has a collection of
Person objects. Where would that property go in the ViewModel? or would you
create ViewModels per row? I've seen that and it's a really bad idea. You
will get all those Person objects from a Service and eventually you will
have to send them back, so you will end up with methods or other objects
dedicated to map from/to Person and PersonViewModel.

Another alternative would be delegation/wrapping instread of mapping, so
your PersonViewModel would take a Person object and delegate, this approach
still has some issues, you won't get rid of the mapping part, since you
still need to map on collection to another collection (we just saved on
mapping the properties), but then you'll end up with a lot of dumb
properties doing delegation (C# 4.0 might solve this with dynamic objects or
WPF with TypeDescriptors).

Anyway, it has work better for us to bind directly to the model for this
type of properties.



On Tue, May 19, 2009 at 11:06 AM, Asheesh Soni <[email protected]>wrote:

> Thanks for the quick replies guys...
> Well, I am using MVVM (Actually, NikhilK's SilverlightFX and modifying his
> Amazon Store sample to my needs...), but being a programmer, I am inherently
> lazy and sometimes need a simple binding expression instead of creating
> converters or properties in the ViewModel.
>
> But I guess you are right... ViewModel is the right spot for this.
>
> Cheers
>
> -Soni
>
>
> On Tue, May 19, 2009 at 10:47 AM, Philip Beadle <[email protected]
> > wrote:
>
>>  Good point, use the View Model to create the combined property from your
>> underlying domain model.
>>
>>
>>
>> Regards,
>>
>> *Philip Beadle*
>> Readify | Principal Consultant
>> Microsoft MVP - ASP/ASP.NET, MCAD, MCT
>>
>> Suite 408 LifeLabs Building | 198 Harbour Esplanade | Docklands | VIC 3008
>> | Australia
>> M: +61 417 301 024 | E: [email protected] | C:
>> [email protected] | W: www.readify.net
>>
>> [image: MIS Email Signature 
>> Banner]<http://readify.net/about-readify/press/readify-makes-2008-mis-strategic-100-list/>
>>
>>
>>
>> *From:* [email protected] [mailto:
>> [email protected]] *On Behalf Of *Jordan Knight
>> *Sent:* Tuesday, 19 May 2009 10:43 AM
>> *To:* [email protected]
>> *Subject:* RE: Silverlight Binding Expressions
>>
>>
>>
>> I'd be either using a) a stack panel with multiple text boxes of b)
>> (prefereably) a view model which supports a "LoggedInAsText" property, which
>> you can do the concats nicely.
>>
>>
>>
>> A ViewModel is simply a class which is passed in to the DataContext and
>> provides nice properties for your UI to bind to, encapsulating the model
>> away from your UI  (preventing the UI from having to be moulded to suit the
>> model)...
>>
>>
>>
>> Have a hunt around for a few MVVM  articles, they are sprouting up more
>> and more.
>>
>>
>>
>> *From:* [email protected] [mailto:
>> [email protected]] *On Behalf Of *Asheesh Soni
>>
>> *Sent:* Tuesday, 19 May 2009 10:37 AM
>> *To:* [email protected]
>> *Subject:* Silverlight Binding Expressions
>>
>>
>>
>> Hello
>>
>> I have a very trivial problem, but all the solutions to it seem to be a
>> bit of an overkill. Just looking for a simple solution....
>>
>> So here's the problem: Bind a Textblock to more than one field.... (or a
>> string and a field)
>>
>> For example: <Textblock Text="{Binding FirstName + " " + LastName}" />
>> Or, <Textblock Text="{Binding "You are logged in as:" + {LoginName}}" />
>>
>> I know the following solutions already:
>>
>> 1. Have two Textblocks with clean and simple bindings.
>> 2. Use a Converter (with ConvertBack for two way binding).
>> 3. Use Xambda (Yeah, I mean a Generic Lambda Converter used in Xaml with a
>> Lambda expression)
>>
>> References for Xambda:
>> http://www.fikrimvarnet/lestirelim/?p=15<http://www.fikrimvar.net/lestirelim/?p=15>
>> http://marlongrech.wordpress.com/2008/02/10/embed-code-in-xaml/
>>
>> And I know advocates of Designer/Developer work flow will argue that
>> embedding complex expressions in Xaml defeats the whole purpose and leads to
>> the bad (or good) old days of spaghetti code. But I guess, having trivial
>> code in Xaml (eg {FirstName} + {LastName}) shouldn't really be a problem.
>>
>> Basically, All I need is a built-in, in-line Converter for one-way binding
>> in Xaml, without having to create my own one line Converters for such
>> trivial transformations.
>>
>> Any ideas?
>>
>>
>> Thanks
>>
>> Soni
>>  ------------------------------
>>
>> Support procedure: https://www.codify.com/lists/support
>> List address: [email protected]
>> Subscribe: [email protected]
>> Unsubscribe: [email protected]
>> List FAQ: http://www.codify.com/lists/ozsilverlight
>> Other lists you might want to join: http://www.codify.com/lists
>>
>> No virus found in this incoming message.
>> Checked by AVG - www.avg.com
>> Version: 8.5.329 / Virus Database: 270.12.32/2118 - Release Date: 05/16/09
>> 17:05:00
>>  ------------------------------
>>
>> Support procedure: https://www.codify.com/lists/support
>> List address: [email protected]
>>
>> Subscribe: [email protected]
>> Unsubscribe: [email protected]
>> List FAQ: http://www.codify.com/lists/ozsilverlight
>> Other lists you might want to join: http://www.codify.com/lists
>>   ------------------------------
>> Support procedure: https://www.codify.com/lists/support
>> List address: [email protected]
>> Subscribe: [email protected]
>> Unsubscribe: [email protected]
>> List FAQ: http://www.codify.com/lists/ozsilverlight
>> Other lists you might want to join: http://www.codify.com/lists
>>
>
>  ------------------------------
> Support procedure: https://www.codify.com/lists/support
> List address: [email protected]
> Subscribe: [email protected]
> Unsubscribe: [email protected]
> List FAQ: http://www.codify.com/lists/ozsilverlight
> Other lists you might want to join: http://www.codify.com/lists
>



-- 
Miguel A. Madero Reyes
www.miguelmadero.com (blog)
[email protected]
--------------------------------------------------------------------------------
Support procedure: https://www.codify.com/lists/support
List address: [email protected]
Subscribe: [email protected]
Unsubscribe: [email protected]
List FAQ: http://www.codify.com/lists/ozsilverlight
Other lists you might want to join: http://www.codify.com/lists

<<image001.jpg>>

Reply via email to