仅在通过ViewModel属性更改ComboBox的SelectedIndex时更改TextBox的值

时间:2017-05-31 12:24:55

标签: wpf combobox

我有ComboBoxTextBox。他们都通过SelectedValueText中的相应DataBinding接收值(即propertiesViewModel)。 更改此SelectedValue中的ComboBox后,我想从TextBoxList<string>的一部分)填充此ViewModel中的新值。 我不想在SelectedIndexChanged使用event ComboBox来选择新的TextBox。来自Text的{​​{1}}的{​​{1}}。我怎么能这样做?

1 个答案:

答案 0 :(得分:1)

在SelectedValue的setter中,您应该修改Text属性的值,并在Text的setter中触发PropertyChanged事件。

    public string SelectedValue
    {
        get { return _selectedValue; }
        set
        {
            _selectedValue = value;
            //here write your code to modify the Text property
        }
    }

    public string Text
    {
        get { return _text; }
        set
        {
            _text = value;
            RaisePropertyChanged(() => Text);
        }
    }