C# WPF可启用绑定

C# WPF可启用绑定,c#,.net,wpf,visual-studio,.net-4.5,C#,.net,Wpf,Visual Studio,.net 4.5,如果值不同于550,我很难理解如何禁用文本框。如果初始值不同于550,则禁用所有值;如果初始值等于550,则启用所有值。问题是当我在UI中更改值时,它不会更新 这是我的xaml <src:CustomTextBox VerticalAlignment = "Center" Text="{Binding TrafoProperties.InsulationLevels.LightningImpulseVoltage,

如果值不同于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}"/>
我的财产

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;
    }

您绑定到
IsEnabled
,这取决于
LightingPulseVoltage
。如果希望在
lightingpulseVoltage
值更改时更新该绑定,则需要在该属性设置器中引发
PropertyChanged
,如下所示:

public double LightningImpulseVoltage
{
    get { return _LightningImpulseVoltage; }
    set 
    { 
        SetProperty(ref _LightningImpulseVoltage, value);
        if (OnLightningImpulseVoltage != null)
            OnLightningImpulseVoltage();
        OnPropertyChanged("IsEnabled");
    }
}

你能拍一张描述你是谁的照片吗doing@HakamFostok基本上,我是从下拉框中选取值,而文本框中表示要禁用的值正在改变。我看不到您曾经为“IsEnabled”提升
PropertyChanged
protected void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
    var eventHandler = this.PropertyChanged;
    if (eventHandler != null)
    {
        eventHandler(this, new PropertyChangedEventArgs(propertyName));
    }
}
public double LightningImpulseVoltage
{
    get { return _LightningImpulseVoltage; }
    set 
    { 
        SetProperty(ref _LightningImpulseVoltage, value);
        if (OnLightningImpulseVoltage != null)
            OnLightningImpulseVoltage();
        OnPropertyChanged("IsEnabled");
    }
}