Silverlight DataBinding Error - Works in WPF. Though!

Start a new Silverlight application ... and in the code behind (in the "Loaded" event) enter 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 resulting error is "The value is not in 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?

0


source to share


2 answers


Currently you cannot use visuals as a data source for data binding in Silverlight 2. I think this will be added for Silverlight v.Next.



+4


source


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



0


source







All Articles