Serialization exception in binding to DataGrid.ItemsSource

Mar 31, 2009 at 9:01 AM
Hello, I use DataGrid as tools to dynamically edit ComboBoxItem in ComboBox.ItemsSource as follows.

 ComboBox cb = new ComboBox();
 List<ComboBoxItem> list = new List<ComboBoxItem>();
 cb.SetBinging(ComboBox.ItemsSourceProperty, new Binding(){ Source = list })
 DataGrid dg = new DataGrid();
 dg.SetBinding(DataGrid.ItemsSourceProperty, new Binding(){ Source = cb.ItemsSource };

And then, I have gotten "Cannot serialize a non-public type 'MS.Internal.NamedObject''" exception in serialization to XAML

 string str = XamlWriter.Save(cb);

In case of StackPanel with RadioButtons, no exceptions has been occured.
 StackPanel sp = new StackPanel();
 sp.Children.Add(new RadioButton(){Content = "radio 1"};
 dg.SetBinding(DataGrid.ItemsSourceProperty, new Binding() { Source = sp.children };
 string str = XamlWriter.Save(sp); // No exception occured.

How can I address ?
Thanks in advance.
May 11, 2009 at 9:00 PM

The datagrid control serializes just fine until you bind it. I've tried binding to all sorts of sources and serialization always

throws the can't serialize named object exception. This may be related to a bug that was fixed in 3.5sp1 the prevented

the serialization of the binding class.

Serializing the binding class is actually a very useful thing for what we do. So a workaround or hotfix would be helpful.