在组合框上绑定selectedItem时出错

时间:2013-10-29 08:11:16

标签: c# wpf xaml data-binding

我想将组合框的选定项目数据绑定到c#属性。当我执行以下操作时,该属性获取值“Suite.Module.RateExperiment.ViewModels.ChamberViewModel”(这不是组合框中所选项目的值):

    <ComboBox DisplayMemberPath="ChamberName" Grid.Column="0" Grid.Row="1" Height="20" VerticalAlignment="Top" ItemsSource="{Binding ChamberCollection}" SelectedValue="{Binding SelectedChamber}">
    </ComboBox>

和c#:

public string SelectedChamber
    {
        get { return _selectedChamber; }
        set
        {
            _selectedChamber = value;
            UpdateChart();
        }
    }

我绑定错误,因为此属性获取此值?

1 个答案:

答案 0 :(得分:1)

SelectedChamber属性应为ChamberViewModel类型,请尝试按以下方式进行更改:

public ChamberViewModel SelectedChamber
    {
        get { return _selectedChamber; }
        set
        {
            _selectedChamber = value;
            UpdateChart();
        }
    }