0

I am currently using the WinRTXamlToolkit's AlternativeFrame control to display multiple pages in a popup, for setting up the ability to post something to reddit. My current problem is that the navigate method for the AlternativeFrame does not appear to work.

Excerpt from 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>

Excerpt from 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));

The first call to Navigate (not above) DOES work, which loads a RUDSubPage1 control. The problem is, the second call to Navigate, as shown above, hangs when I make the call. It never returns, so the await remains stuck on it forever. RUDSubPage2 is very nearly empty in its xaml and code behind files, so nothing in it is interfering the the Navigate method. Any ideas why this isn't working?

Edit: Ok, I found the troublesome line in the WinRTXamlToolkit code.

    /// <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);
        }
    }

For some reason, the line above will always hang in my app after I try calling the Navigate method a second time. Anyone know why it might be doing this?

Filip Skakun
  • 31,624
  • 6
  • 74
  • 100
Nkosi Dean
  • 227
  • 8
  • 18
  • Where in `RedditUploadDialog.xaml.cs` are you calling the `Navigate` function? – Nate Diamond Apr 04 '14 at 20:27
  • Can you share a repro project? Have you tried debugging it with the source code rather than NuGet package? – Filip Skakun Apr 04 '14 at 21:15
  • The navigate function is called in a button pressed event of the RedditUploadDialog.xaml.cs file. And I'll try using the source code and building it instead of the Nuget package, so I can properly step through it with the debugger. I didn't really think to do that. – Nkosi Dean Apr 05 '14 at 05:53
  • Are you using `AlternativePage` instead of `Page` with the frame? – Filip Skakun Apr 05 '14 at 19:56
  • Yes, I amusing AlternativePage and not Page, and I also tried debugging using the source code of WinRTXamlToolkit (I built it and included it as a project in my solution), but I end up getting the "No Source Available" error from Visual Studio when I try stepping into the Navigate method, without any option to even locate the source file. – Nkosi Dean Apr 05 '14 at 21:41

1 Answers1

1

I decided to just comment out the troublesome line that I found in my original post, and now everything works. This isn't really a good solution, as I hate doing things like this to make things work, but I can't figure out why that line of code makes my program hang. Thanks for the help.

Nkosi Dean
  • 227
  • 8
  • 18