简体   繁体   中英

Combobox SelectedValue isn't working?

I have created a combobox in xaml like this:

ComboBox x:Name="cbTest" SelectedValue="{Binding TestSpeed}" HorizontalAlignment="Left" Margin="0,10,0,0" Width="250" SelectionChanged="cbTest_SelectionChanged"/>

And the Combobox is filled with the following items:

        for (int i = 1; i < 6; i++)
            cbTest.Items.Add(i);

I see the items in the combobox, but it doesn't show the SelectedValue what I choose before. This is the property:

private short _testSpeed;
public short TestSpeed
{
    get
    {
        return _testSpeed;
    }
    set
    {
        _testSpeed= value;
        NotifyPropertyChanged();
    }
}

And this is when I change the item on SelectedChanged

 _vm.TestSpeed = (short)Convert.ToInt16(cbTest.SelectedValue);

TestSpeed gives me the correct data in debug, but the selectedValue binding isn't working!?

在您的具体情况结合模式必须OneWayToSource喜欢SelectedValue="{Binding Path=TestSpeed, Mode=OneWayToSource}当TestSpeed是。 stringint这是工作,当short -不工作,我认为你需要编写特定的转换器使用short或使用int不用担心

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM