Note that there are some explanatory texts on larger screens.

plurals
  1. POWpf Time Traveling in a ComboBox
    primarykey
    data
    text
    <p>I have a combobox inside my Window.xaml which I initialize with it's property SelectedIndex having the value 0 and with it's property SelectedItem having a Binding to a viewmodel's property.</p> <p>Sounds pretty easy and basically like this:</p> <pre><code>&lt;ComboBox SelectedItem = "{Binding MyChosenItem}" SelectedIndex="0" ItemsSource={Binding MyList} /&gt; </code></pre> <p>Now inside my MyList which is a simple list of string, the first entry is looking like this: "---NULL--". Its just a static entry indicating that user havent selected anything yet.</p> <p>Once I start my application the combobox sets its SelectedItem to "---NULL---" because of SelectedIndex = 0 and futhermore MyChosenItem gets also set to "---NULL---" since that is the combobox's SelectedItem.</p> <p>So far so good but now I would like to tearch the combobox to knows that once I have a value in MyChosenItem the combox may not set the selection to "---NULL---".</p> <p>Here is an example:</p> <p>If MyChosenItem = null then Combobox shall pick "---NULL---" as standard value though when MyChosenItem = "BMW" the combobox shall pick BMW as selected item which is the 4th item inside the MyList.</p> <p>How do I do this in WPF? The problem is SelectedIndex which always tries to set the first item as selected item but I need the 4th one. Do I need to time travel to the point after the first item is set and then I set combobox's SelectedItem to 4th one?</p> <p>Any ideas? Did somebody stumble upon this already in past?</p> <p><strong>Edit: I forgot to mention the combobox is a third party control and they somehow set manually SelectedIndex = 0 so I have no chance to change that. Therefore I beg you guys to stick to the requirements give in this question and I hope somebody figures some way to solve this or at least a nice workaround.</strong></p>
    singulars
    1. This table or related slice is empty.
    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.
 

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