繁体   English   中英

组合框SelectedValue无法正常工作?

[英]Combobox SelectedValue isn't working?

我在xaml中创建了一个组合框,如下所示:

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

组合框填充了以下项目:

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

我在组合框中看到了项目,但没有显示SelectedValue我之前选择的内容。 这是属性:

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

这是我更改SelectedChanged上的项目时

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

TestSpeed在调试时为我提供了正确的数据,但是selectedValue绑定不起作用!

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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