[英]How do I change the text property of a Textblock in WPF?
I have a Form in WPF and a DispatcherTimer, every time the tick event fires I want to change the value of OrderLbl.Text from "Today's orders" to "this week's orders", and from "this week's orders to "This Month's Orders".我在 WPF 和 DispatcherTimer 中有一个表单,每次触发滴答事件时,我都想将 OrderLbl.Text 的值从“今天的订单”更改为“本周的订单”,并从“本周的订单”更改为“本月的订单” .
However, when I attempt to change the value of OrderLbl.text from the _timer_Tick event, it throws an exception saying an object reference is required, however when I reference this inside the tick event it will not change the value of OrderLbl.Text但是,当我尝试从 _timer_Tick 事件更改 OrderLbl.text 的值时,它会抛出一个异常,指出需要对象引用,但是当我在滴答事件中引用它时,它不会更改 OrderLbl.Text 的值
Code is below;代码如下;
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
//}
}
Remove the static
keyword from the Tick
handler:从
Tick
处理程序中删除static
关键字:
private void _timer_Tick(Object sender, EventArgs e)
{
...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.