[英]Combobox text property twoway binding not working
I have a ComboBox as below 我有一个ComboBox如下
<ComboBox VerticalAlignment="Center"
Width="83.84"
Canvas.Left="626.24"
Canvas.Top="249.088" DataContext="{Binding Items[0]}"
Text="{Binding TextVariable, Mode=TwoWay, NotifyOnValidationError=True, TargetNullValue='', ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"
Height="68.293"
Style="{StaticResource ComboBoxDialogControlQ69_74}" />
The problem is: when I set the value for TextVariable
in my view model it gets displayed on UI. 问题是:当我在视图模型中设置TextVariable
的值时,它会在UI上显示。 But when I change it on UI it is not updated in the property. 但是当我在UI上更改它时,它不会在属性中更新。
I think I am missing something very obvious, any help is appreciated. 我想我错过了一些非常明显的东西,感谢任何帮助。
It works really good when i tried doing like below for Text binding on ComboBox, 当我尝试在ComboBox上进行文本绑定时,它的效果非常好,
Text="{Binding TextVariable, Mode=TwoWay, UpdateSourceTrigger=LostFocus, NotifyOnValidationError=True, TargetNullValue='', ValidatesOnDataErrors=True, ValidatesOnExceptions=True}"
I have added one more property to make it editable. 我添加了一个属性以使其可编辑。
IsEditable="True"
if you need the change on PropertyChange change UpdateSourceTrigger to PropertyChanged 如果需要对PropertyChange进行更改,请将UpdateSourceTrigger更改为PropertyChanged
UpdateSourceTrigger=PropertyChanged
VM VM
public string TextVariable {
get
{ return _TextVariable; }
set
{
_TextVariable = value;
NotifyPropertyChanged();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.