I am a beginner programmer c# WPF. It is required to make a status bar on the main window, but with any changes on the pages, it should change. That is, changes from other classes (pages) should occur. This gives an error about the availability of the stream. Tried to do it through: Thread - the error is that the element is occupied by another thread, I tried to specify this object through the locker and change the values in it, it did not work; BackgroundWorker - Nothing happened at all on RunWorkerAsync; Events - unable to call invoke from another page.
Window - MainWindow(this elements State) StateBorder, StateText - elements State in window I usually have a method START and a thread is created in it that changes the text and background of the state elements
internal class SetState
{
private Window Window { get; set; }
private Border StateBorder { get; set; }
private TextBlock StateText { get; set; }
public static List<State> States = new List<State>() {
new State(2, Brushes.Yellow), new State(4, Brushes.Red),
new State(1, Brushes.LightGreen), new State(5, Brushes.LightGray) };
public static SetState CurState { get; set; }
public SetState(Window mainWindow)
{
Window = mainWindow;
StateBorder = mainWindow.FindName("StateBorder") as Border;
StateText = mainWindow.FindName("StateText") as TextBlock;
}
public void Start(NewState o)
{
Thread t = new Thread(ReState);
t.Start(o);
}
public void ReState(object o)
{
if (o is NewState State)
{
State state = States.Find(u => u.id == State.Id);
CurState.StateBorder.Background = state.Color;
CurState.StateText.Text = State.Message;
}
}