在Windows 10中检测到布局周期,但在Windows 8.1中检测不到

时间:2016-04-21 05:53:19

标签: c# windows windows-store-apps windows-10-universal windows-8.1-universal

我正在使用一个计时器,每隔10秒更新一次布局,直到进度条没有完全填满。

在Windows 8.1中似乎没有问题,但在Windows 10中,抛出了布局周期检测异常。

1 个答案:

答案 0 :(得分:2)

原始代码是

private void SetVerticalOffSet()
        {
            Popup ParentPopup = this.Parent as Popup;

            if (ParentPopup == null)
                return;

            double ActualVerticalOffset = ParentPopup.VerticalOffset;
            double ActualHorizontalOffset = ParentPopup.HorizontalOffset;

            double NewVerticalOffset = (Window.Current.Bounds.Height - DecryptionDialog_MainGrid.ActualHeight) / 2;
            double NewHorizontalOffset = (Window.Current.Bounds.Width - DecryptionDialog_MainGrid.ActualWidth) / 2;
            if (ActualVerticalOffset != NewVerticalOffset || ActualHorizontalOffset != NewHorizontalOffset)
            {
                ParentPopup.VerticalOffset = NewVerticalOffset;
                ParentPopup.HorizontalOffset = NewHorizontalOffset;
            }
        }

每次更新布局时都会调用它。

if块导致无限循环为ActualVerticalOffSet& ActualHorizo​​ntalOffSet在Windows 10中保持不变(在十进制的第10位)

if (ActualVerticalOffset != NewVerticalOffset || ActualHorizontalOffset != NewHorizontalOffset)
        {
            ParentPopup.VerticalOffset = NewVerticalOffset;
            ParentPopup.HorizontalOffset = NewHorizontalOffset;
        }

此修复的暂定解决方案是

if (Math.Round(ActualVerticalOffset) != Math.Round(NewVerticalOffset) ||     Math.Round(ActualHorizontalOffset) != Math.Round(NewHorizontalOffset))
{
        ParentPopup.VerticalOffset = NewVerticalOffset;
        ParentPopup.HorizontalOffset = NewHorizontalOffset;
}

直到微软上映