简体   繁体   中英

Function doesn't work, but it must work

private void Main_OnLayoutUpdated(object sender, EventArgs e)
{
    label1.Content = Classes.Global.X.ToString();
    Classes.Global.PositionChanged(this);
}

PositionChanged writes to X new x-position of window. It works, but as soon as I delete label1 it stops working. No errors.

My guess, Classes.Global.X does something ( perhaps creates a singleton? ) and PositionChanged checks to see if something is null that x would of created and hence does nothing?

try var x = Classes.Global.X instead of the label.

如果删除label1,则尝试将任何内容设置为label1可能会通过被忽略的异常,可能是对象处置异常或null引用异常会导致该异常,请尝试将所有内容包装在try catch中并记录该异常。

I'll take a stab here and suggest not deleting label1, but simply setting label1's visible property to false.

At least that way you can maintain the method and not break the app.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM