I'd like to bind dynamic properties to WinForms control properties.
In the following example I bind the IsAlive property of a thread to the Enabled of a button.
using System;
using System.Windows.Forms;
using System.Threading;
namespace ThreadTest
{
public partial class Form1 : Form
{
Thread thread;
public Form1()
{
InitializeComponent();
thread = new Thread(() =>
{
while (true)
Thread.Sleep(125);
}
);
button2.DataBindings.Add("Enabled", thread, "IsAlive");
}
private void buttonStart_Click(object sender, EventArgs e)
{
thread.Start();
}
private void buttonStop_Click(object sender, EventArgs e)
{
// ...
}
}
}
This only works on start up. The "Stop" button is disabled because the thread is not alive. When I click on button "Start" I would expect to change button "Stop" to enabled. But it does not.
Am I missing something or is this just not possible?