WPF Update a user control embedded into my window
Posted on 2016-09-19
I am trying to update a user control in my windows and it doesn't work. MSDN says that you have to use the UI thread to update it but with all the examples all over the place - nothing works...
I have a user control for a status which every window gets:
bw.WorkerReportsProgress = true;
bw.WorkerSupportsCancellation = false;
public void setStatusBar(ErrorValues ev)
tbxStatusBar.Text = ev.strErrorMessage;
tbxStatusBar.TextWrapping = TextWrapping.Wrap;
tbxStatusBar.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
tbxStatusBar.VerticalScrollBarVisibility = ScrollBarVisibility.Auto;
I am trying to update the status from a window which contains the text box in the XAML and the code behind is the same windows code behind:
public void UsersOpen()
var ev = new ErrorValues();
ev.strMessageType = "BAD";
ev.strErrorMessage = "HOLY CODE DICK TRACY!!";
private void setStatus(ErrorValues ev)
var stat = new StatusBar();
Dispatcher.Invoke(() => Dispatcher.BeginInvoke((Action)(() => stat.setStatusBar(ev))));
I have tried Invoke, BeginInvoke and dozens of other ways but this is very elusive. So I am going to have 20 windows with this control that need to push messages to the control so it is displayed on the window.
Any help is greatly appreciated!