.NET Zone is brought to you in partnership with:

My name is Toni Petrina and I am a software developer and an occasional speaker. Although I primarily develop on the Microsoft stack, I like to learn new technologies. My hobbyist projects range from game development, regardless of the technology, to ALM. I spend most of my time with my girlfriend and someday I will learn how to play the guitar properly. Toni is a DZone MVB and is not an employee of DZone and has posted 69 posts at DZone. You can read more from them at their website. View Full User Profile

Data Binding: Windows Phone 7 Cannot Access Private/Internal Functions, But Windows Phone 8 Can

  • submit to reddit

I’ve previously noticed a particular problem with reflection differences between WP7 and WP8 and I noted them when I wrote about quickly generating JSON from anonymous objects. It appeared that on Windows Phone 7 reflection cannot access private/internal functions and thus cannot serialize anonymous objects.

This is also true when using data binding to private/internal view model. On a recent Stack Overflow question – Binding on Windows Phone 7 does not work, a user encountered a problem with his code not working on Windows Phone 7 while working on Windows Phone 8.

The issue was that the view model is not public. This is really easy to reproduce, just create an internal view model and use it as a DataContext.

class MainViewModel
	public string Text { get { return "Hello world"; } }

As for the view, simply bind to the Text property:

<TextBlock Text="{Binding Text}" />

The project will correctly work on Windows Phone 8 devices and emulators, but it won’t work on Windows Phone 7 devices and emulators.

Expected result – only on WP8.

Turning on breaking on every thrown exception in the Exceptions dialog (as seen on the image below) will ensure that his error is caught during debugging.

Enabling breaking whenever an exception is thrown

Until next time, happy coding.

Published at DZone with permission of Toni Petrina, author and DZone MVB. (source)

(Note: Opinions expressed in this article and its replies are the opinions of their respective authors and not those of DZone, Inc.)