0

我目前正在使用 WinRTXamlToolkit 的 AlternativeFrame 控件在弹出窗口中显示多个页面,以设置将内容发布到 reddit 的功能。我目前的问题是 AlternativeFrame 的导航方法似乎不起作用。

摘自 RedditUploadDialog.xaml

<ScrollViewer HorizontalAlignment="Left" Margin="10,130,0,0" VerticalAlignment="Top" Width="480" Height="310" VerticalScrollBarVisibility="Hidden">
            <Controls:AlternativeFrame x:Name="scrollingFrame" extensions:FrameworkElementExtensions.ClipToBounds="True">
                <Controls:AlternativeFrame.PageTransition>
                    <Controls:PushTransition ForwardDirection="Random" BackwardDirection="Random" />
                </Controls:AlternativeFrame.PageTransition>
            </Controls:AlternativeFrame>
        </ScrollViewer>

摘自 RedditUploadDialog.xaml.cs

/*"scrollingFrame" is an AlternativeFrame control inside of a scrollviewer. RUDSubPage2 is an */AlternativePage control. RUDSubPage2's code page does not have any code in it except for the InitializeComponents method in the 
await this.scrollingFrame.Navigate(typeof(RUDSubPage2));

第一次调用 Navigate(不在上面)确实有效,它加载了 RUDSubPage1 控件。问题是,当我拨打电话时,对 Navigate 的第二次调用(如上所示)挂起。它永远不会返回,所以 await 永远停留在它上面。RUDSubPage2 在其 xaml 和代码隐藏文件中几乎是空的,因此其中没有任何内容会干扰 Navigate 方法。任何想法为什么这不起作用?

编辑:好的,我在 WinRTXamlToolkit 代码中找到了麻烦的行。

    /// <summary>
    /// Contains extension methods to wait for FrameworkElement events.
    /// </summary>
    public static class FrameworkElementExtensions
    {
        /// <summary>
        /// Waits for the element to load (construct and add to the main object tree).
        /// </summary>
        public static async Task WaitForLoadedAsync(this FrameworkElement frameworkElement)
        {
            if (frameworkElement.IsInVisualTree())
                return;

            //This line, right here, is the one that keeps hanging. This method is called from within the Navigate method of the AlternativeFrame control. Also, frameworkElement here is the AlternativeFrame while the code is running.
            await EventAsync.FromRoutedEvent(
                eh => frameworkElement.Loaded += eh,
                eh => frameworkElement.Loaded -= eh);
        }
    }

出于某种原因,在我再次尝试调用 Navigate 方法后,上面的行将始终挂在我的应用程序中。任何人都知道它为什么会这样做?

4

1 回答 1

1

我决定只注释掉我在原始帖子中发现的麻烦行,现在一切正常。这不是一个很好的解决方案,因为我讨厌做这样的事情来使事情正常进行,但我不明白为什么那行代码会让我的程序挂起。谢谢您的帮助。

于 2014-04-06T23:46:36.180 回答