I couldn't find a simple solution to this problem. That's why I'm asking.
I have a WPF window like this:
<Window x:Class="WPF_Test.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="640" Height="480">
<Button Name="xaml_button" Content="A Text."/>
</Window>
And a MainWindow class:
using System.Windows;
using System.Threading;
namespace WPF_Test
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
xaml_button.Content = "Text changed on start.";
}
}
private void xaml_button_Click()
{
Threading.t1.Start();
UIControl.ChangeButtonName("Updated from another CLASS.");
}
}
The button's Content
property successfully changed itself. But what I want to do, is to change the property in another class or thread. What I tried is this:
class UIControl
{
public static void ChangeButtonName(string text)
{
var window = new MainWindow();
window.xaml_button.Content = text;
}
}
It obviously doesn't work, because the public MainWindow()
changes the Content
property back to the original one, and brings some issues along with it.
Also I want to use this while multithreading. My simple threading class looks like this:
class Threading
{
public static Thread t1 = new Thread(t1_data);
static void t1_data()
{
Thread.Sleep(2000);
UIControl.ChangeButtonName("Updated from another THREAD.");
}
}