<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.silverlight.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Report a Silverlight Bug</title><link>http://forums.silverlight.net/forums/28.aspx</link><description>Found a bug in Silverlight? Use this forum to describe the bug and the code or steps to reproduce it.</description><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>Re: Re: Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/246648.aspx</link><pubDate>Fri, 10 Jul 2009 19:39:20 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:246648</guid><dc:creator>burt52</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/246648.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=246648</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/silverlight/images/icon-quote.gif"&gt; &lt;strong&gt;KooeeMan:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;Calling combo.Measure(new Size(combo.ActualWidth, combo.ActualHeight) just after setting itemsSource worked for me.&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;
&lt;p&gt;AWESOME, DUDE!&amp;nbsp; I don&amp;#39;t know why it works or why you thought of it, but you just saved my butt! Thanks!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Re: Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/237694.aspx</link><pubDate>Thu, 25 Jun 2009 09:26:00 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:237694</guid><dc:creator>KooeeMan</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/237694.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=237694</wfw:commentRss><description>Calling combo.Measure(new Size(combo.ActualWidth, combo.ActualHeight) just after setting itemsSource worked for me.</description></item><item><title>Re: Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/219324.aspx</link><pubDate>Wed, 13 May 2009 14:31:57 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:219324</guid><dc:creator>PaxTerminus</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/219324.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=219324</wfw:commentRss><description>&lt;p&gt;Yes, so far the &amp;quot;brute force&amp;quot; solution is the only one that works. I keep my combo-box in canvas and than remove it from the children collection and add a new combo-box in its place. At least all the event subroutines and references work as long as the name is the same (so the program can be coded as if it was the same combo box and intelli-sense works as it should).&lt;/p&gt;
&lt;p&gt;With the&amp;nbsp;new object method&amp;nbsp;it seems that the update of the combo-box content through asynchronous means while&amp;nbsp;the list&amp;nbsp;is open works too. Of course the Selected Item value has to be stored in some other variable as well for the re-selection in the new object.&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;cnvProdTypePH.Children.Clear()&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;cbxProdType = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;New&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; ComboBox&lt;/font&gt;&lt;/p&gt;&lt;font size="2"&gt;cbxProdType.Height = 20: &lt;/font&gt;&lt;font size="2"&gt;cbxProdType.Width = 60&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;&amp;#39;So the new box has the size of the original one in my case&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#008000" size="2"&gt;&lt;/font&gt;&lt;/font&gt; 
&lt;p&gt;cnvProdTypePH.Children.Add(cbxProdType)&lt;/p&gt;
&lt;p&gt;cbxProdType.ItemsSource = m_lstProductAll&lt;/p&gt;
&lt;p&gt;cbxProdType.SelectedItem = m_lstProductAll.Item(0)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;/font&gt;</description></item><item><title>Re: Re: Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/214338.aspx</link><pubDate>Thu, 30 Apr 2009 22:31:33 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:214338</guid><dc:creator>Mobolo</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/214338.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=214338</wfw:commentRss><description>&lt;p&gt;In case it helps anyone else....&lt;/p&gt;
&lt;p&gt;I had this issue with a combo box that was dynamically created in a datagrid.&amp;nbsp; The DataGrid has it&amp;#39;s own problem with selected rows dissapearing (or blanking out rather).&amp;nbsp; The fix for that also solved this issue, after setting the ItemSource of the grid, call YourGrid.Focus();&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/164195.aspx</link><pubDate>Wed, 21 Jan 2009 20:56:14 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:164195</guid><dc:creator>chris69nz</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/164195.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=164195</wfw:commentRss><description>&lt;p&gt;The suggestions also don&amp;#39;t work for me.&amp;nbsp; Only real solution was to remove the combobox from visual tree completely and re-add in later on once the data is re-populated.&amp;nbsp; Using observablecollection and calling UpdateLayout didn&amp;#39;t work.&amp;nbsp; Therefore I think there are several bugs that cause this error.&lt;/p&gt;
&lt;p&gt;I get the exact same error in this situation which I haven&amp;#39;t been able to resolve at all:&amp;nbsp; If the user has the drop down open, the web service call comes back and updates the list, the error occurs.&amp;nbsp; I&amp;#39;ve tried setting IsDropDown to false before updating the itemssource, calling UpdateLayout, all without any luck.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;My overall impression of the combobox is that it is really buggy and not ready for actual use unless you have a really simple use for it.&amp;nbsp; Messing around with the visual tree to work around bugs destroys productivity and using MVVM pattern.&amp;nbsp; I&amp;#39;ve had to rewrite a lot of code (based on WPF)&amp;nbsp;just to avoid bugs with this control.&lt;/p&gt;
&lt;p&gt;These bugs and the tooltip bug (&lt;a href="https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=387409"&gt;https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=387409&lt;/a&gt;) really makes me consider suspending SL development until its ready for primetime, as they&amp;#39;re almost showstoppers.&amp;nbsp; I really hope they fix them asap and send updates out.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/156006.aspx</link><pubDate>Mon, 05 Jan 2009 13:59:04 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:156006</guid><dc:creator>surrounded</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/156006.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=156006</wfw:commentRss><description>&lt;p&gt;Just to add&amp;nbsp;to this link.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Recently, I ran into the same issue documented in this link.&amp;nbsp; The suggestions did not work.&amp;nbsp; The way I resolved it was as follows:&lt;/p&gt;
&lt;p&gt;I am adding comboboxes to a stackpanel, which is added to a border, which is added to a popup window.&amp;nbsp; I have a case statement which allows the user to select a section, township, and range (STR), each from a separate combobox,&amp;nbsp;and zoom to it.&amp;nbsp; In order for the user to be able to execute more than one zoom (ie. go back and chose a different STR) I had to create the comboboxes new each time; such as pCombobox = new combobox();.&amp;nbsp; While I use UpdateLayout(), it seems to have no effect - I can comment it out and get the same results.&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/140921.aspx</link><pubDate>Tue, 02 Dec 2008 13:52:24 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:140921</guid><dc:creator>Urieal</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/140921.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=140921</wfw:commentRss><description>&lt;p&gt;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/silverlight/images/icon-quote.gif"&gt; &lt;strong&gt;kellywhite:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;&lt;/p&gt;&lt;p&gt;I used the workaround from the link mentioned in the first post of this thread and am no longer experiencing this error.&amp;nbsp; Besure to call &lt;strong&gt;UpdateLayout()&lt;/strong&gt;&lt;/p&gt;&lt;p&gt;
&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;This worked for me as well. However, I call UpdateLayout() prior to explicitly changing my SelectedIndex...&lt;/p&gt;&lt;p&gt;eg&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;pre class="coloredcode"&gt;uxComboBox.UpdateLayout();
uxComboBox.SelectedIndex = i + 1;&lt;/pre&gt;&amp;nbsp;&amp;nbsp;</description></item><item><title>Re: Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/139865.aspx</link><pubDate>Mon, 01 Dec 2008 03:50:55 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:139865</guid><dc:creator>kellywhite</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/139865.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=139865</wfw:commentRss><description>&lt;p&gt;I used the workaround from the link mentioned in the first post of this thread and am no longer experiencing this error.&amp;nbsp; Besure to call &lt;strong&gt;UpdateLayout()&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;List&amp;lt;ComboBoxItem&amp;gt; itemList = new List&amp;lt;ComboBoxItem&amp;gt;();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ComboBoxItem selectedItem = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; foreach (var p in AllProjectsData.Projects.Where(p =&amp;gt; p.Status == status))&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; ComboBoxItem item = new ComboBoxItem();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; item.Content = p.Name;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; item.DataContext = p;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; itemList.Add(item);&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (projectId == p.Id)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; selectedItem = item;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; projectList.ItemsSource = itemList;&lt;br /&gt;&lt;strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; projectList.UpdateLayout();&lt;/strong&gt;&lt;/p&gt;</description></item><item><title>Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/139861.aspx</link><pubDate>Mon, 01 Dec 2008 03:43:26 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:139861</guid><dc:creator>kellywhite</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/139861.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=139861</wfw:commentRss><description>&lt;p&gt;I also am still receiving this error, and I&amp;#39;m also showing/hiding the usercontrol which displays the combobox.&amp;nbsp; Changing the code to use an ObservableCollection&amp;lt;ComboBoxItem&amp;gt; does not get rid of this error.&lt;/p&gt;</description></item><item><title>Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/129127.aspx</link><pubDate>Tue, 11 Nov 2008 19:52:48 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:129127</guid><dc:creator>jregehr</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/129127.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=129127</wfw:commentRss><description>&lt;p&gt;@Giganoid&lt;/p&gt;&lt;p&gt;If you&amp;#39;re using complex items are you using the ComboBox.ItemTemplate element to style the combobox items?&amp;nbsp; If so you shouldn&amp;#39;t need the DisplayMemberPath attribute for your combobox.&lt;/p&gt;&lt;p&gt;You should just be able to set ComboBox.ItemsSource = [instanceOfObservableCollection] once and from then on just mess with (add/remove items) the ObservableCollection object instance - the combobox should stay in sync.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;- Jonathan &lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/129113.aspx</link><pubDate>Tue, 11 Nov 2008 19:26:29 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:129113</guid><dc:creator>Giganoid</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/129113.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=129113</wfw:commentRss><description>&lt;p&gt;@Jonathan&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;In my ComboBoxItems are complex objects with texts, images (relative to the text) and sometimes different colors.&lt;/p&gt;
&lt;p&gt;What is the correct value for DisplayMemberPath in this case?&amp;nbsp;Is there any chance to solve such a problem with a DisplayMemberPath-Expression?&lt;/p&gt;</description></item><item><title>Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/128957.aspx</link><pubDate>Tue, 11 Nov 2008 15:26:34 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:128957</guid><dc:creator>jregehr</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/128957.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=128957</wfw:commentRss><description>&lt;p&gt;Giganoid, if you&amp;#39;re seeing empty items, be sure to set the DisplayMemberPath on the combobox to a member of the objects contained in the list that you&amp;#39;re using as the backing collection for the ComboBox ItemsSource.&lt;/p&gt;&lt;p&gt;For example (code shortened for readability)&lt;/p&gt;&lt;p&gt;public class Person {&lt;br /&gt;&lt;/p&gt;&lt;blockquote&gt;public string Name { get; set; }&lt;br /&gt;public string Address { get; set; }&lt;br /&gt;// other stuff left out&lt;br /&gt;&lt;/blockquote&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;List&amp;lt;Person&amp;gt; people = new List&amp;lt;Person&amp;gt;();&lt;/p&gt;&lt;p&gt;ComboBox cb = new ComboBox {&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;ItemsSource = people,&lt;br /&gt;DisplayMemberPath = &amp;quot;Name&amp;quot;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;}&lt;br /&gt;&lt;/p&gt;&lt;p&gt;// Add stuff to the list and it should show up in the combobox.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Let me know if you have more questions.&lt;/p&gt;&lt;p&gt;- Jonathan &lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/127113.aspx</link><pubDate>Sat, 08 Nov 2008 06:45:37 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:127113</guid><dc:creator>PistachioPirate</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/127113.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=127113</wfw:commentRss><description>&lt;p&gt;I&amp;#39;ve been messing with the same problem for the last few hours, but without doing any data binding.&amp;nbsp; I can recreate it with the following example:&lt;/p&gt;
&lt;p&gt;page.xaml:&lt;/p&gt;
&lt;p&gt;&amp;lt;UserControl x:Class=&amp;quot;ComboBoxTest.Page&amp;quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlns=&amp;quot;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;http://schemas.microsoft.com/winfx/2006/xaml/presentation&lt;/a&gt;&amp;quot; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; xmlns:x=&amp;quot;&lt;a href="http://schemas.microsoft.com/winfx/2006/xaml"&gt;http://schemas.microsoft.com/winfx/2006/xaml&lt;/a&gt;&amp;quot; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Width=&amp;quot;400&amp;quot; Height=&amp;quot;300&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Grid x:Name=&amp;quot;LayoutRoot&amp;quot; Background=&amp;quot;Blue&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Button x:Name=&amp;quot;btnShowDialog&amp;quot; Content=&amp;quot;Show Dialog&amp;quot; Width=&amp;quot;120&amp;quot; Height=&amp;quot;20&amp;quot; Click=&amp;quot;btnShowDialog_Click&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;StackPanel x:Name=&amp;quot;MyDialog&amp;quot; Width=&amp;quot;200&amp;quot; Height=&amp;quot;100&amp;quot; Orientation=&amp;quot;Vertical&amp;quot; Background=&amp;quot;Green&amp;quot; Visibility=&amp;quot;Collapsed&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;ComboBox x:Name=&amp;quot;cbxStuff&amp;quot; Width=&amp;quot;150&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;Button x:Name=&amp;quot;btnOk&amp;quot; Content=&amp;quot;Ok&amp;quot; Width=&amp;quot;40&amp;quot; Click=&amp;quot;btnOk_Click&amp;quot; /&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/StackPanel&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/Grid&amp;gt;&lt;br /&gt;&amp;lt;/UserControl&amp;gt;&lt;/p&gt;
&lt;p&gt;page.xaml.cs:&lt;/p&gt;
&lt;p&gt;using System;&lt;br /&gt;using System.Net;&lt;br /&gt;using System.Windows;&lt;br /&gt;using System.Windows.Controls;&lt;br /&gt;using System.Windows.Input;&lt;/p&gt;
&lt;p&gt;namespace ComboBoxTest&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; public partial class Page : UserControl&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; public Page()&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; InitializeComponent();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void btnShowDialog_Click(object sender, RoutedEventArgs e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cbxStuff.Items.Clear();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cbxStuff.Items.Add(&amp;quot;Stuff&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cbxStuff.Items.Add(&amp;quot;More Stuff&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cbxStuff.SelectedIndex = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cbxStuff.UpdateLayout();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyDialog.Visibility = Visibility.Visible;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void btnOk_Click(object sender, RoutedEventArgs e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyDialog.Visibility = Visibility.Collapsed;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;}&lt;/p&gt;
&lt;p&gt;It starts off just showing a button.&amp;nbsp; Press the button to show the dialog (which has a combobox, and a button which hides the dialog).&lt;/p&gt;
&lt;p&gt;If you just press the buttons, showing and hiding the dialog, the error does not occur.&amp;nbsp; If, however, you:&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;1) Press the button to show the dialog (dialog appears)&lt;br /&gt;2) Interact with the combobox in any way&lt;br /&gt;3) Press the button to hide the dialog (dialog disappears)&lt;br /&gt;4) Press the button to show the dialog (Error occurs)&lt;/p&gt;
&lt;p&gt;Error always seems to happen at the &amp;#39;MyDialog.Visibility = Visibility.Visible&amp;#39; line.&lt;/p&gt;
&lt;p&gt;Now, if you change the btnShowDialog_Click() method to the following:&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; private void btnShowDialog_Click(object sender, RoutedEventArgs e)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cbxStuff.Items.Clear();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cbxStuff.Items.Add(&amp;quot;Stuff&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cbxStuff.Items.Add(&amp;quot;More Stuff&amp;quot;);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; MyDialog.Visibility = Visibility.Visible;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cbxStuff.UpdateLayout();&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; cbxStuff.SelectedIndex = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;then the error no longer occurs.&amp;nbsp; Strange.&amp;nbsp; Seems the control misbehaves when hidden, but acts as expected when visible.&lt;/p&gt;</description></item><item><title>Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/126893.aspx</link><pubDate>Fri, 07 Nov 2008 19:12:32 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:126893</guid><dc:creator>Giganoid</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/126893.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=126893</wfw:commentRss><description>&lt;p&gt;Hi Jonathan,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;i&amp;#39;ve integrated your idea in my sampe above. But it didnt worked. I saw only empty Items in the Combobox. Can you do it better? The problem is to bind &amp;quot;old&amp;quot; items to a new instance of a Combobox.&lt;/p&gt;
&lt;p&gt;XAML: (the same)&lt;/p&gt;
&lt;p&gt;C#:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;namespace&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; SilverlightErrorTest&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;partial&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Page&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; : &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;UserControl&lt;/p&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;
&lt;p&gt;{&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;private&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;List&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBoxItem&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;gt; _Items = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;List&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBoxItem&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;gt;() { &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBoxItem&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;() { Content = &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;Item1&amp;quot;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; }, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBoxItem&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;() { Content = &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;Item2&amp;quot;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; }, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBoxItem&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;() { Content = &lt;/font&gt;&lt;font color="#a31515" size="2"&gt;&lt;font color="#a31515" size="2"&gt;&amp;quot;Item3&amp;quot;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; } };&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;private&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBox&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; _ComboBox = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBox&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;() { HorizontalAlignment = &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;HorizontalAlignment&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.Left, VerticalAlignment = &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;VerticalAlignment&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.Top, Margin = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Thickness&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;(0, 50, 0, 0) };&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;private&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ObservableCollection&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBoxItem&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;gt; _UsedItems = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ObservableCollection&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;lt;&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBoxItem&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&amp;gt;();&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; Page()&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;{&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;this&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.Loaded += &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;RoutedEventHandler&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;(Page_Loaded);&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;InitializeComponent();&lt;/p&gt;
&lt;p&gt;_ComboBox.ItemsSource = _UsedItems;&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;private&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; Page_Loaded(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;object&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; sender, &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;RoutedEventArgs&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; e)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;LayoutRoot.Children.Add(_ComboBox);&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;foreach&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBoxItem&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; m_Item &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;in&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; _Items)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;_UsedItems.Add(m_Item);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;private&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; Clicked(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;object&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; sender, &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;RoutedEventArgs&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; e)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;LayoutRoot.Children.Remove(_ComboBox);&lt;/p&gt;_ComboBox = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;;&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;_UsedItems.Clear();&lt;/p&gt;_ComboBox = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBox&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;() { HorizontalAlignment = &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;HorizontalAlignment&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.Left, VerticalAlignment = &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;VerticalAlignment&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;.Top, Margin = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;Thickness&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt;(0, 50, 0, 0), ItemsSource = _UsedItems };&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;LayoutRoot.Children.Add(_ComboBox);&lt;/p&gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;foreach&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; (&lt;/font&gt;&lt;font color="#2b91af" size="2"&gt;&lt;font color="#2b91af" size="2"&gt;ComboBoxItem&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; m_Item &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;font color="#0000ff" size="2"&gt;in&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; _Items)&lt;/font&gt;&lt;/font&gt;&lt;font size="2"&gt; 
&lt;p&gt;{&lt;/p&gt;
&lt;p&gt;_UsedItems.Add(m_Item);&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;
&lt;p&gt;}&lt;/p&gt;&lt;/font&gt;</description></item><item><title>Re: Combobox databind error: Sys.InvalidOperationException: Managed RuntimeError error #4004 in control 'ctl02'</title><link>http://forums.silverlight.net/forums/thread/126182.aspx</link><pubDate>Thu, 06 Nov 2008 20:26:10 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:126182</guid><dc:creator>jregehr</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/126182.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=28&amp;PostID=126182</wfw:commentRss><description>&lt;p&gt;I had a similar issue with a combobox.&amp;nbsp; I&amp;#39;d been stumped on it for a few days, especially because the stack trace was in .Net framework code and didn&amp;#39;t reference my code at all.&amp;nbsp; The hint that pointed me in the right direction was &amp;quot;&lt;font size="2"&gt;&lt;em&gt;Value does not fall within the expected range&lt;/em&gt;&lt;/font&gt;&amp;quot;.&lt;/p&gt;&lt;p&gt;As it turns out, the issue is one of timing.&amp;nbsp; If the itemsSource is changed right before any UI portion of the combobox is manipulated it causes the problem.&amp;nbsp; For example the code below will cause the error.&amp;nbsp; I believe it has to do with the
time (read: latency) taken by the layout system to update the visuals
on the ComboBox and its associated itemsControl, vs. the lack of time (read: immediacy) between when the ItemsSource is changed and the SelectedItem is assigned.&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;myComboBox.ItemsSource = {some list}&lt;br /&gt;myComboBox.SelectedItem = {some member of the above list}&lt;br /&gt;[immediate UI crash]&lt;br /&gt;&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;I also found a pretty easy way around it.&amp;nbsp; Apply an empty list to the ComboBox.ItemsSource as the combobox is created or the visual is initialized.&amp;nbsp; Then, add items into the list.&amp;nbsp; That seems to trigger the layout manager to behave differently than if a new collection is applied to the ItemsSource.&amp;nbsp; For example, the code below executes successfully.&amp;nbsp; It&amp;#39;s important to use the ObservableCollection for the combobox items to update automagically.&lt;br /&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;// using System.Collections.ObjectModel.ObservableCollection;&lt;br /&gt;ObservableCollection myList = new ObservableCollection();&lt;br /&gt;myComboBox.ItemsSource = myList // the list may or may not be empty, but it is important to assign it here&lt;br /&gt;&lt;/p&gt;&lt;p&gt;...&amp;nbsp; execution returns to the user thread, the layout updates, and user interaction fires ...&lt;/p&gt;&lt;p&gt;&lt;br /&gt;myList.Add({some object}); // the collection notifies the combobox it has new item(s).&lt;br /&gt;myComboBox.SelectedIndex = {some Object};&lt;br /&gt;myComboBox.InvalidateMeasure(); // unnecessary, but helpful, especially if the list was empty before the line above.&lt;/p&gt;&lt;/blockquote&gt;&lt;p&gt;Let me know if you have any questions, and please mark this as the solution if it works for you.&lt;/p&gt;&lt;p&gt;Thanks,&lt;/p&gt;&lt;p&gt;- Jonathan Regehr &lt;br /&gt;&lt;/p&gt;&lt;blockquote&gt;&lt;p&gt;&amp;nbsp;&lt;br /&gt;&lt;/p&gt;&lt;/blockquote&gt;</description></item></channel></rss>