VB Magic

2012/03/02

Databinding Fail on Windows Phone, if using a TextBox and an AppBar Button

Filed under: .NET, VB.NET, Windows Phone 7 — Tags: , , — vbmagic @ 10:14 pm

An annoying bug (Or Feature) of developing for Windows Phone 7.1.

I’ve been writing a Windows Phone 7.1 app that uses the MVVM model. I have a view that allows me to enter some text and the only other thing on the view is an App Bar button which saves the text.

From what I can gather, the data binding will cause an update once the text box has lost focus. But in this case pressing the App Bar button does not cause the text box to lose focus, so the data update doesn’t happen.

In my case it was an easy work around to give the TextBox a name and update the view model from within the code behind.


TextBox Text="{Binding Path=SomeText, Mode=TwoWay}" x:Name="aTextBox" Grid.Row="1"


_viewModel.SomeText = aTextBox.Text
_viewModel.Save()

But it sort of defeats the object of data bound items.

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Blog at WordPress.com.

%d bloggers like this: