Over a million developers have joined DZone.

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


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 , DZone MVB .

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}