Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It sounds like your ComboBox has its SelectedItem or SelectedValue property bound to something that isn't allowed to be null. So when you try to clear the collection that the ComboBox's Items property is bound to, it's trying to assign "null" to that property and an exception is being raised.</p> <p>There's probably a really nice WPF-y way to get around it. I'd probably start by trying to temporarily suspend the binding by setting its update mode to Explicit and then clear the collection:</p> <pre><code>var binding = BindingOperations.GetBinding(myCmdBox, ComboBox.SelectedItemProperty); binding.UpdateSourceTrigger = UpdateSourceTrigger.Explicit; myObservableCollection.Clear(); // repopulate the collection here binding.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged; </code></pre> <p>That's just a suggestion. I might be barking up the wrong tree but it might give you some clues as to why you're getting the error.</p> <p><strong>Update</strong></p> <p>Wow - that's a lot of code. Shame you couldn't reduce it down to the bare minimum necessary to reproduce the problem.</p> <p>I'm assuming your exception is being thrown from within the <code>cmbRecipeType_SelectionChanged</code> event handler. If that's the case, you have two options:</p> <ol> <li><p>Put a breakpoint inside that method and find out what's throwing the exception. It's probably something simple, like this first line yielding a null value:</p> <p>string selectedRecipeType = cmbRecipeType.SelectedItem as string;</p></li> </ol> <p>If that's true, you could probably whack this in straight after that:</p> <pre><code>if (selectedRecipeType == null) return; </code></pre> <p>Which will prevent any subsequent code from accessing selectedRecipeType as if it's non-null.</p> <ol start="2"> <li>Do something similar to what I originally suggested, and temporarily unhook that event handler from your ComboBox before you clear the items. Then hook it up again straight after.</li> </ol>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload