2017-07-19 61 views
0

我想在將窗口顯示爲對話框之前清除WPF窗口內的TextBlock文本。文本塊文本僅在調用ShowDialog窗口時清除WPF

但TextBlock上的文本顯示一秒的先前值,然後自動清除。

有沒有可能在將窗口顯示爲對話框之前清除文本?

這裏是我的代碼片段:

//Code in Window Control: 
public string PopupTitle 
{ 
    get 
    { 
     string response = string.Empty; 
     this.Dispatcher.Invoke((Action)delegate 
     { 
      response = lbl_PopupTitle.Text; 
     }, null); 
     return response; 
    } 
    set 
    { 
     this.Dispatcher.Invoke((Action)delegate 
     { 
      lbl_PopupTitle.Text = value; 
      lbl_PopupTitle.Visibility = string.IsNullOrEmpty(value) ? Visibility.Collapsed : Visibility.Visible; 
     }, null); 
    } 
} 

//Code to call this window: 

PopupWindow popup = new PopupWindow(); 
popup.PopupTitle = string.Empty; 
popup.ShowDialog(); 

回答

1

你爲什麼要調用的setter Dispatcher.Invoke?如果要在ShowDialog方法被調用之前立即重置文本,請不要這樣做:

​​