{"id":40,"date":"2011-07-11T18:58:00","date_gmt":"2011-07-11T16:58:00","guid":{"rendered":"http:\/\/pustekuchen.xn--burkfrulein-q8a.de\/?p=40"},"modified":"2011-07-11T18:58:00","modified_gmt":"2011-07-11T16:58:00","slug":"set-selectedindex-in-a-selectionchanged-event","status":"publish","type":"post","link":"https:\/\/blog.bur-k.de\/?p=40","title":{"rendered":"Set SelectedIndex in a SelectionChanged Event"},"content":{"rendered":"

Hello folks,<\/p>\n

today i got a wierd problem in my Silverlight Application. I had two Comboboxes, i wanted to change the items of the second Combobox, when i select a value in the first Combobox.<\/p>\n

But the second Combobox still showed another value. After spending some time with google i found this topic.<\/a><\/p>\n

The solution to that Problem is the following.<\/p>\n

\n\n\n\n
\n
private void cmbOne_SelectionChanged(object sender, SelectionChangedEventArgs e)\n{\n    cmbTwo.Dispatcher.BeginInvoke(new Action(() => { cmbTwo.SelectedIndex = 0; }));\n}<\/pre>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n

The BeginInvoke<\/a> Method executes the specified delegate asynchronously with the specified arguments on the thread that the Dispatcher<\/a> was created on.<\/p>\n

Now its works how it should. I hope it will help someone \":)\"<\/p>\n

<\/div>