简体   繁体   English

wpf IsEnabled按钮绑定,仅工作一次……已经有PropertyChange通知

[英]wpf IsEnabled button binding, only works once…already have PropertyChange notification

here is my xaml: 这是我的xaml:

<Button 
 x:Name="StartBtn" 
 Content="Start"
 Command="{Binding StartProcess}"
 HorizontalAlignment="Left"
 Height="23" 
 Margin="241,181,0,0" 
 VerticalAlignment="Top"
 Width="57" 
 Grid.Column="1" 
 IsEnabled="{Binding IsStartButtonEnabled}"/>

here is my property: 这是我的财产:

 private bool _isStartButtonEnabled;
        public bool IsStartButtonEnabled
        {
            get { return _isStartButtonEnabled; }
            set
            {
                _isStartButtonEnabled = value;
                OnPropertyChanged("IsStartButtonEnabled");
            }
        }

it works with whatever i set it to on startup, but when i manipulate the bool later in the code, the change is not reflected in the WPF. 它可以与我在启动时将其设置为的任何值一起使用,但是当我稍后在代码中操作布尔值时,更改不会反映在WPF中。 I do have the data context set correctly as other bindings all function perfectly. 我确实正确设置了数据上下文,因为其他绑定都可以正常运行。

Also when I manipulate the Bool in the code I am using the property and not the private field. 同样,当我在代码中操作Bool时,我使用的是属性,而不是私有字段。

private void OnStartProcess()
        {
            IsStartButtonEnabled = false;
            //stuff
        }

It is working, make sure you are setting the public property in your code and not the private field: 它正在工作,请确保您在代码中设置了公共属性,而不是私有字段:

   public RelayCommand StartProcess
    {
        get
        {
            return new RelayCommand(Execute);
        }
    }

    private void Execute()
    {
        IsStartButtonEnabled = false;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM