Derik Whittaker

Syndication

News


PSA: Help my binding is not updating my View Model…. Check your Mode

This is simply a PSA as I spent 10 minutes today scratching my head why my Property Change notification was not being fired when I edited some text boxes in a WP7 application. 

I knew my binding was setup because the values in my ViewModel we showing up in my View, but when I would make a change to the text box the value was NOT being pushed back into my ViewModel.

Once I determined that my binding was setup correctly (ok, kinda correctly) I bounced over to my XAML and realized I forgot to set the mode in my binding. Make sure your binding looks like below if you want your changes to be pushed into your ViewModel.

{Binding State, Mode=TwoWay}

If you forget to put the Mode=TwoWay you will NOT get updates

Till next time,


Posted 06-06-2010 10:28 AM by Derik Whittaker
Filed under: ,

[Advertisement]

Comments

OneMan wrote re: PSA: Help my binding is not updating my View Model…. Check your Mode
on 06-06-2010 12:45 PM

Isnt Mode=TwoWay supposed to be default?

Derik Whittaker wrote re: PSA: Help my binding is not updating my View Model…. Check your Mode
on 06-06-2010 1:17 PM

@OneMan,

Good question.  This is w/ Silverlight for WP7 (which is Silverlight v3) so I do not know.  All i know is that without this set i did not get 2 way binding.  When I set it I did.

A quick google search did not lead me to see what the default was.

Rob Eisenberg wrote re: PSA: Help my binding is not updating my View Model…. Check your Mode
on 06-06-2010 4:48 PM

In WPF, when a DependencyProperty is declared, you can specify metadata which indicates which binding mode should be the default mode for that property. In WPF the default binding mode for TextBox is TwoWay by default. However, Silverlight (all versions to date) does not have a mechanism to declare this particular type of metadata for a DP and the binding system at its core does not support this concept. As a result, all bindings in Silverlight are OneWay by default...which happens to be very unintuitive in a number of scenrios and very problematic if you are porting a WPF application to Silverlight.  It's a pain and many developers, MVPs, etc have asked repeatedly for this to be fixed. Who knows if it ever will?

Derik Whittaker wrote re: PSA: Help my binding is not updating my View Model…. Check your Mode
on 06-06-2010 4:58 PM

Rob,

Thanks for the insight.  Should have known you would know the answer :)

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)