Question

Start a new Silverlight application... and in the code behind (in the "Loaded" event), put this code:

// This will *NOT* cause an error.
this.LayoutRoot.DataContext = new string[5];

But...

// This *WILL* cause an error!
this.LayoutRoot.DataContext = this;

The error that is raised is "Value does not fall within the expected range." BTW, this code works 100% in regular WPF (Windows development), and there should be no reason why it won't work in WPF/E :)

Any thoughts?

Was it helpful?

Solution

You can't currently use visual elements as a data source for data binding in Silverlight 2. I think this is slated to be added for Silverlight v.Next.

OTHER TIPS

You can use visual elements as data source if you create binding directly in the code, but trying to assign visual element to DataContext will throw ArgumentException. It doesn't make much sense, but silverlight is just on version 2.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top