我有三个文本框,文本绑定到三个属性。当我输入第三个文本框时,我需要禁用两个文本框。我必须清除禁用文本框的值。
`
<TextBox Text="{Binding TextProperty1}" IsEnabled="{Binding T1Enabled}"/>
<TextBox Text="{Binding TextProperty2}" IsEnabled="{Binding T2Enabled}"/>
<TextBox Text="{Binding TextProperty3}" IsEnabled="{Binding T3Enabled}"/>`
T1-3 3Enabled是一个只有getter的属性,我在文本框的“丢失焦点”命令中引发属性更改。当这些属性刷新时,我将清除禁用文本框(TextProperty1-3)的绑定属性。
但是,当某些禁用的文本框出现验证错误时,源属性将被清除,但textbox.text未被清除。
如何在mvvm中解决这个问题?我不想设置textbox.text。
我希望问题是清楚的。感谢您的帮助或其他解决方案。
发布于 2018-08-31 10:51:36
我用派生的textbox类解决了这个问题。
public class MyTextBox : TextBox
{
public MyTextBox()
{
IsEnabledChanged += MyTextBox_IsEnabledChanged;
}
private void MyTextBox_IsEnabledChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if(e.NewValue is bool)
if (!(bool)e.NewValue)
Text = string.Empty;
}
}https://stackoverflow.com/questions/52097395
复制相似问题