簡體   English   中英

WPF-屬性更改時綁定控件未更新?

[英]WPF - Bound Control Not Updating When Property Changed?

我已經將TextBox的Text屬性綁定到基礎對象的屬性,並且看起來工作得很好。 不幸的是,當我以編程方式更改屬性的值時,它似乎並未在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
        }
    }
}

當設置另一個屬性時,將設置該屬性的值:

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:

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

弗拉德的解決方案(在評論中)是正確的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM