簡體   English   中英

如何更改 WPF 中 Textblock 的文本屬性?

[英]How do I change the text property of a Textblock in WPF?

我在 WPF 和 DispatcherTimer 中有一個表單,每次觸發滴答事件時,我都想將 OrderLbl.Text 的值從“今天的訂單”更改為“本周的訂單”,並從“本周的訂單”更改為“本月的訂單” .

但是,當我嘗試從 _timer_Tick 事件更改 OrderLbl.text 的值時,它會拋出一個異常,指出需要對象引用,但是當我在滴答事件中引用它時,它不會更改 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
        //}

    }

Tick處理程序中刪除static關鍵字:

private void _timer_Tick(Object sender, EventArgs e)
{
    ...
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM