Einstellung combobox Standard-Wert mit SelectedIndex

Warum ist das immer, wenn ich versuche SlectedIndex auf 0, es bleibt immer -1 ?

public partial class Window1 : Window
{
    private ObservableCollection<string> _dropDownValues = new ObservableCollection<string>();
    public ObservableCollection<string> DropDownValues
    {
        get { return _dropDownValues; }
        set { _dropDownValues = value; }
    }

    private string _selectedValue;
    public string SelectedValue
    {
        get { return _selectedValue; }
        set { _selectedValue = value; }
    }

    public Window1()
    {
        InitializeComponent();
        DataContext = this;

        DropDownValues.Add("item1");
        DropDownValues.Add("item2");
        DropDownValues.Add("item3");
        DropDownValues.Add("item4");
        DropDownValues.Add("item5");
        DropDownValues.Add("item6");

        if (combotest.SelectedIndex == -1)
        {
            combotest.SelectedIndex = 0;
        }
    }
}

<StackPanel HorizontalAlignment="Left" Margin="10">
        <ComboBox Name="combotest"
            Margin="0 0 0 5"
            ItemsSource="{Binding DropDownValues}"
            SelectedValue="{Binding SelectedValue}"        
            Width="150"/>     
    </StackPanel>
InformationsquelleAutor Adrian | 2011-09-05
Schreibe einen Kommentar