동적 속성을 WinForms 컨트롤 속성에 바인딩하고 싶습니다.동적 속성을 WinForms 컨트롤 속성에 바인딩 할 수 있습니까?
다음 예제에서는 스레드의 IsAlive 속성을 단추를 사용하도록 바인딩합니다.
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)
{
// ...
}
}
}
이것은 시작시에만 작동합니다. 쓰레드가 살아 있지 않기 때문에 "Stop"버튼이 비활성화됩니다. "Start"버튼을 클릭하면 "Stop"버튼이 활성화되어있을 것으로 예상됩니다. 그러나 그렇지 않습니다.
내가 누락되었거나 그냥 가능하지 않습니까?