开发者

Function doesn't work, but it must work

private void Main_OnLayoutUpdated(object sender, EventArgs e)
{
    label1.Content = Classes.Glo开发者_运维知识库bal.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.


If you delete label1, then trying to set anything to label1 will probably through an exception which is ignored, may be object disposed exception or null reference exception would cause it, try wrapping everything in try catch and log the exception.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜