locked
Porting Windows Phone NavigateUri To Windows 8 Frame.Navigate RRS feed

  • Question

  • This question was posted on stackoverflow, but didn't receive any valuable answers.
    I figured you guys might be able to answer it.

    I'm porting one of my Windows Phone 8 apps to Windows 8 and I'm having a navigation issue.

    string publishingpoint = "http://some.domain.name/directory/file.isml/manifest";

    Windows Phone 8 C#:

    HyperlinkButton hyperlinkbutton = new HyperlinkButton();
    hyperlinkbutton.NavigateUri = new Uri("/player.xaml?publishingpoint=" + publishingpoint, UriKind.Relative);

    Windows 8 C#:

    this.Frame.Navigate(typeof(player), publishingpoint);

    I can bind a control to the appropriate command, in XAML, with Click="".  The problem is that I'm creating the control with C# and I haven't found a property that I can set this.Frame.* to.

    How can I perform this navigation, using the new Windows 8 navigation methods?
    JJ

    Friday, January 10, 2014 3:35 AM

Answers

  • Hi,

    You can define a HyperlinkButton click event in code behind:

    HyperlinkButton hyperlinkbutton = new HyperlinkButton(); hyperlinkbutton.Click+=hyperlinkbutton_Click; ...

    void hyperlinkbutton_Click(object sender, RoutedEventArgs e)
    {
      
    this.Frame.Navigate(typeof(player), publishingpoint);

    }



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, January 15, 2014 5:43 AM

All replies

  • Can you provide some more specific details? Are you navigating to a page within your app called 'player'? What error message do you get?

    It seems like 'player' is a user control, not a page. I don't think you can Frame.Navigate to a user control, only a <Page>.

    If my assumptions are correct, try navigating to a page, and set the page's content to be your 'player' control.

    this.Frame.Navigate(typeof(emptyPage), publishingpoint);

    Add your control as the only UI element in your emptyPage class.

    If I'm totally wrong, please provide extra details and someone should be able to figure out the issue.


    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

    Friday, January 10, 2014 3:50 AM
  • Thanks for the quick response...

    As noted in the Windows Phone code, the receiving page is player.xaml.
    In this particular case, I'm using Microsoft's Player Framework.
    The publishingpoint string is the address of a Microsoft Smooth Streaming video.

    My whole player.xaml is below:

    <Page
        x:Name="pageRoot"
        x:Class="FlcLive_Windows8.Player"
        DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="using:FlcLive_Windows8"
        xmlns:common="using:FlcLive_Windows8.Common"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:mmppf="using:Microsoft.PlayerFramework"
        xmlns:adaptive="using:Microsoft.PlayerFramework.Adaptive"
        mc:Ignorable="d">
    
        <!--
            This grid acts as a root panel for the page that defines two rows:
            * Row 0 contains the back button and page title
            * Row 1 contains the rest of the page layout
        -->
        <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
            <Grid.ChildrenTransitions>
                <TransitionCollection>
                    <EntranceThemeTransition/>
                </TransitionCollection>
            </Grid.ChildrenTransitions>
            <Grid.RowDefinitions>
                <RowDefinition Height="140"/>
                <RowDefinition Height="*"/>
            </Grid.RowDefinitions>
    
            <!-- Back button and page title -->
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="120"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>
                <Button x:Name="backButton" Margin="39,59,39,0" Command="{Binding NavigationHelper.GoBackCommand, ElementName=pageRoot}"
                            Style="{StaticResource NavigationBackButtonNormalStyle}"
                            VerticalAlignment="Top"
                            AutomationProperties.Name="Back"
                            AutomationProperties.AutomationId="BackButton"
                            AutomationProperties.ItemType="Navigation Button"/>
                <TextBlock x:Name="pageTitle" Text="" Style="{StaticResource HeaderTextBlockStyle}" Grid.Column="1" 
                            IsHitTestVisible="false" TextWrapping="NoWrap" VerticalAlignment="Bottom" Margin="0,0,30,40"/>
            </Grid>
    
            <!--
                TODO: Content should be placed within the following grid 
                      to show details for the current item
            -->
            <Grid Grid.Row="1" x:Name="contentRegion">
                <mmppf:MediaPlayer x:Name="MediaPlayer" IsGoLiveVisible="True" IsResolutionIndicatorVisible="True" IsSignalStrengthVisible="True" IsVolumeVisible="True">
                    <mmppf:MediaPlayer.Plugins>
                        <adaptive:AdaptivePlugin />
                    </mmppf:MediaPlayer.Plugins>
                </mmppf:MediaPlayer>
            </Grid>
        </Grid>
    </Page>

    mmppf:MediaPlayer needs Source="" to know what video to play.
    In my Windows Phone app, using HyperlinkButton's NavigateUri's ability to include a query string, it's trivial to dynamically create the link.
    Then, it's a simple function to parse the query string:

    protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        string publishingpoint = "";
        if (NavigationContext.QueryString.TryGetValue("publishingpoint", out publishingpoint))
        {
            Player.Source = new Uri(publishingpoint, UriKind.Absolute);
        }
    }

    But, Windows 8 doesn't seem to like that (specifically, NavigationContext).
    In my research, the new Windows 8'y way of doing it is with Frame.Navigate().
    The problem is that I haven't figured out how to get the publishingpoint string into the second portion of Navigate().

    Hopefully, that makes what I'm trying to accomplish clear.
    I can post as much code and describe it as much as you need.
    Once I get this hurdle jumped, it's submission time.
    JJ


    • Edited by Fa310tx Friday, January 10, 2014 4:19 AM
    Friday, January 10, 2014 4:17 AM
  • So in a nutshell the issue is that you're not able to pass your 'publishingpoint' variable to the page you are navigating to (but navigation itself is actually working fine)?

    I'm not at my dev PC right now, so I can't post code (and I use VB.net, not C#), but I think what you need to do is get your passed variable via e.NavigationParameter in your OnNavigatedTo method in 'player.xaml.cs'.

    Something like (warning: I don't know C#...):

    string variableReceivedFromPreviousPage = e.NavigationParameter;

    Once you have captured that variable you can do whatever you want with it, of course. I use this method (though I'm relying on memory for the actual line of code above and it could be wrong, and might be only the 8.1 way of doing it).


    I'm a self-taught noob amateur. Please take this into account when responding to my posts or when taking advice from me.

    Friday, January 10, 2014 4:34 AM
  • If you know of a way to parse the NavigateUri, then that would be a very simple fix.
    I wasn't able to get my parsing code to work and I saw no examples of how to do it with Windows 8 (other than Frame.Navigate).
    The initial effort was to figure out how to set Frame.Navigate's query string from C#, though.
    JJ

    Friday, January 10, 2014 6:08 AM
  • Hi,

    You can Navigate to player.xaml page and pass parameter to that page in the HyperlinkButton click event:

    void hyperlinkButtin_Click(object sender, RoutedEventArgs e)
    {
       this.Frame.Navigate(typeof(player), publishingpoint);
     
    }
    

    And in the Player page navigationHelper_LoadState method you can get the parameter:

    private void navigationHelper_LoadState(object sender, LoadStateEventArgs e)
    {
        string publishingpoint = e.NavigationParameter as string;
    
     }
    

    Refer to the link below:

    http://msdn.microsoft.com/en-us/library/windows/apps/hh771188.aspx

    See the Passing information between pages in that link you can get more detail information.

    Best Wishes!


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, January 14, 2014 3:37 AM
  • Thanks for the reply, although I already know how to do the linking in Windows 8.
    The problem with all of the tutorials is that they assume the HyperlinkButton is created in XAML with a Click="" event.
    In my case, I'm creating the HyperlinkButton in C#.

    That's the whole problem.
    I need to figure out how to set the link to the new page and the query string within C#.
    JJ

    Wednesday, January 15, 2014 3:09 AM
  • Hi,

    You can define a HyperlinkButton click event in code behind:

    HyperlinkButton hyperlinkbutton = new HyperlinkButton(); hyperlinkbutton.Click+=hyperlinkbutton_Click; ...

    void hyperlinkbutton_Click(object sender, RoutedEventArgs e)
    {
      
    this.Frame.Navigate(typeof(player), publishingpoint);

    }



    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to &quot;Mark as Answer&quot; the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, January 15, 2014 5:43 AM
  • Thanks for the reply...
    I'm working on it, right now, and there seems to be one issue.
    How does the publishingpoint variable get to Navigate()?.
    hyperlinkbutton_Click isn't passing it.

    Maybe I can create a global variable for publishingpoint, but that seems kind of backwards.
    It would make sense to do hyperlinkbutton_Click(publishingpoint), but I'm getting this error...
    Cannot implicity convert type 'void' 'Windows.UI.Xaml.RoutedEventHandler'

    Any other ideas?
    It seems like this is the best answer, but not quite there.
    JJ

    Edit...
    I ended up creating a bunch of global variables and click functions.
    It seems like a really inefficient way of working, though.
    Using NavigatUri was so easy, why change?
    JJ


    • Edited by Fa310tx Sunday, January 26, 2014 1:05 AM
    Saturday, January 25, 2014 11:19 PM