【发布时间】:2015-11-05 14:32:22
【问题描述】:
如果值不同于 550,我无法理解如何禁用文本框。如果初始值不同于 550,则禁用所有值,或者如果初始值等于 550,则启用所有值。问题是它不会当我在 UI 中更改值时更新。
这是我的 xaml
<src:CustomTextBox VerticalAlignment = "Center"
Text="{Binding TrafoProperties.InsulationLevels.LightningImpulseVoltage,
UpdateSourceTrigger = PropertyChanged,
Mode = TwoWay,
ValidatesOnNotifyDataErrors = True,
NotifyOnValidationError = True}"
Validation.ErrorTemplate = "{StaticResource defaultErrorTemplate}"
IsEnabled="{Binding Path = TrafoProperties.InsulationLevels.IsEnabled, Mode = TwoWay}"/>
还有我的两个属性
public double LightningImpulseVoltage
{
get { return _LightningImpulseVoltage; }
set
{
SetProperty(ref _LightningImpulseVoltage, value);
if (OnLightningImpulseVoltage != null)
OnLightningImpulseVoltage();
}
}
public bool IsEnabled
{
get { return LightningImpulseVoltage == 550; }
set
{
OnPropertyChanged("LightningImpulseVoltage");
}
}
我的设置属性
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] String propertyName = null)
{
if (object.Equals(storage, value))
return false;
storage = value;
this.OnPropertyChanged(propertyName);
return true;
}
还有我的 OnPropertyChanged
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
var eventHandler = this.PropertyChanged;
if (eventHandler != null)
{
eventHandler(this, new PropertyChangedEventArgs(propertyName));
}
}
【问题讨论】:
-
你能放一个描述你在做什么的屏幕截图
-
@HakamFostok 基本上我是从下拉框中选择值,而文本框中的值会被禁用
-
我没有看到你为“IsEnabled”提过
PropertyChanged。
标签: c# .net wpf visual-studio .net-4.5