This task should be quite simple, but nothing I tried has worked. I’m just trying to get the text to go away when the button is clicked, and while data is loaded and validated.
I’ve tried the following, which doesn’t force a redraw:
private delegate void InlineDelegate();
private void btnLogon_Click(object sender, RoutedEventArgs e)
{
lblInvalidLogon.Dispatcher.Invoke(new InlineDelegate(() =>
{
lblInvalidLogon.Content = string.Empty;
lblInvalidLogon.InvalidateVisual();
}), System.Windows.Threading.DispatcherPriority.Render, null);
//
// Process to verify logon credentials...
//
}
I’ve also tried DispatcherPriority.Send, and I’ve placed a Thread.Sleep following the Invoke to give it plenty of time to update the UI, but nothing I’ve tried will force the UI to update while the authentication process continues.
Phil correctly pointed out the cause:
Was working on this, and came up with the solution right at the same time as his comment. I’ve solved it as below: