WPF - LayoutUpdated event firing repeatedly

前提是你 提交于 2019-11-29 10:04:45

If you're updating the UI from the EventHandler you attached to the LayoutUpdated event, this will also trigger that event!

For example:

    void my_LayoutUpdatedEvent(object sender, EventArgs e)
    {
        textBlock1.Text = "changed";
        Console.Out.WriteLine("text changed!");
    }

will go into an infinite loop of updates.

Perhaps you need to do something like this:

    void my_BetterLayoutUpdatedEvent(object sender, EventArgs e)
    {
        if (!hasChanged)
            textBlock1.Text = "changed";
        hasChanged = true;
        Console.Out.WriteLine("text changed!");
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!