-1
我在WPF和DispatcherTimer中有一個表單,每當tick事件觸發時,我想將OrderLbl.Text的值從「今日訂單」更改爲「本週訂單」,並將「本週訂單」更改爲「本月Orders「如何更改WPF中Textblock的文本屬性?
但是,當我嘗試從_timer_Tick事件中更改OrderLbl.text的值時,它會引發一個異常,指出需要引用對象,但是當我在tick事件中引用它時,它不會更改的OrderLbl.Text
代碼值低於;
public void Start()
{
System.Windows.Threading.DispatcherTimer DTimer = new System.Windows.Threading.DispatcherTimer();
DTimer.Tick += new EventHandler(_timer_Tick);
DTimer.Interval = new TimeSpan(0, 0, 5);
DTimer.Start();
}
private static void _timer_Tick(Object sender, EventArgs e)
{
if (OrderLbl.Text == "Today's Orders")
{
OrderLbl.Text = "This Week's Orders";
}
else if (OrderLbl.Text == "This Week's Orders")
{
OrderLbl.Text = "This Month's Orders";
}
//else
//{
// mw.orderlbl.text= "today's orders";
// go
//}
}
您確定您的文本框名稱是correcT嗎? OrderLbl聽起來是一個標籤 – Sajeetharan
是的,我特意做了這件事,因爲我希望我的TextBlock能夠模擬標籤的功能。 –