开发者

WPF - Bound Control Not Updating When Property Changed?

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.

Here's the property:

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;
开发者_JAVA百科                this.SealedDate = DateTime.MinValue.ToString();
            }
            base.OnChanged();
        }
    }
}

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜