Reputation: 227
I am trying to clear a TextBlock text which is inside a WPF window, before showing the Window as Dialog.
But the Text on TextBlock shows the Previous Value for a second, and then gets cleared automatically.
Is there any possibility I can clear text before showing window as Dialog?
Here is my code snippet:
//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();
Upvotes: 0
Views: 86
Reputation: 169340
Why are you calling Dispatcher.Invoke
in the setter? Don't do this if you want to reset the text immediately before the ShowDialog
method is called:
set
{
lbl_PopupTitle.Text = value;
lbl_PopupTitle.Visibility = string.IsNullOrEmpty(value) ? Visibility.Collapsed : Visibility.Visible;
}
Upvotes: 1