我有一个像这样的视图树观察器:
rowsContainerVto = rowsContainerView.ViewTreeObserver;
rowsContainerVto.GlobalLayout += RowsContainerVto_GlobalLayout;
void RowsContainerVto_GlobalLayout (object sender, EventArgs e)
{
if(rowsContainerVto.IsAlive)
rowsContainerVto.GlobalLayout -= RowsContainerVto_GlobalLayout;
vW = rowsContainerView.Width;
Console.WriteLine ("\r now width is " + vW);
}
它应该做的是在布局视图后找到宽度,它做得很好。我只是不知道如何阻止它一遍又一遍地运行。
以上基本上是基于提出的建议。这只会使应用程序崩溃。当我摆脱“IsAlive”时,循环将永远继续。在第一次绘制和布局之后,我似乎无法找到阻止它的方法。