WPF-属性更改时绑定控件未更新?

问题描述:

我已经将TextBox的Text属性绑定到基础对象的属性,并且看起来工作得很好.不幸的是,当我以编程方式更改属性的值时,它似乎并未在GUI上更新.

I've bound the Text property of a TextBox to a base object's property and it seems to work just fine. Unfortunately, when I programatically change the value of the property, it doesn't seem to update on the GUI.

这里是属性:

public string SealedDate
{
    get
    {
        string result = string.Empty;

        if (_DACase.SealedDate != DateTime.MinValue)
        {
            result = Formatting.FormatDate(_DACase.SealedDate);
        }

        return result;
    }
    set
    {
        DateTime theDate = DateTime.MinValue;

        if (DateTime.TryParse(value, out theDate)
            && _DACase.SealedDate != theDate)
        {
            _DACase.SealedDate = theDate;
            base.OnChanged(); //fires event so I know the value of the object has changed
        }
    }
}

当设置另一个属性时,将设置该属性的值:

And the value of that property is being set when another property it being set:

public bool IsSealed
{
    get
    {
        return _DACase.SealedId > 0
            || _DACase.SealedDate != DateTime.MinValue;
    }
    set
    {
        if (value != (_DACase.SealedId > 0 || _DACase.SealedDate != DateTime.MinValue))
        {
            if (value)
            {
                this.SealedId = Authentication.CurrentUser.Id;
                this.SealedDate = Formatting.FormatDate(DateTime.Now);
            }
            else
            {
                this.SealedId = 0;
                this.SealedDate = DateTime.MinValue.ToString();
            }
            base.OnChanged();
        }
    }
}

以及当我认为它应该更新时不会更新的TextBox的XAML:

And the XAML of the TextBox that isn't updating when I think it should:

<TextBox Name="txtSealedDate" Text="{Binding SealedDate}" Grid.Column="5" Grid.Row="3" IsReadOnly="True" />

弗拉德的解决方案(在注释中)是正确的.

Vlad's solution (in the comments) was correct.