locked
NavigationService.Navigate does not work in a Silverlight Navigation App RRS feed

  • Question

  • After creating a new Silverlight 4 Navigation App, navigations works with Uri Mapping but I can't navigate from one page to another using

    NavigationService.Navigate.  A simple example is to add a button to the Home Page and use the button's click event to navigate in the code behind: this.NavigationService.Navigate(new Uri("/Views/About.xaml", UriKind.Relative)); produces the error

    An unkown error was encountered.  Please contact your administrator for more information:

    Page not found: /Views/About.xaml

    However the home and about buttons tied to the Uri Mapper work as does updating the browser uri.  I have tried all kinds of combinations and can't get any of them to work using NavigationService.Navigate.  Can someone explain how this works?

    Tuesday, March 23, 2010 7:06 AM

Answers

  •  Why you don't use the uri mapper?

    <navigation:Frame>
    	<navigation:Frame.UriMapper>
    		<uriMapper:UriMapper>
    			<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
    		</uriMapper:UriMapper>
    	</navigation:Frame.UriMapper>
    </navigation:Frame>
    NavigationService.Navigate(new Uri("/About", UriKind.Relative));
     
    Tuesday, March 23, 2010 8:20 AM

All replies

  •  Why you don't use the uri mapper?

    <navigation:Frame>
    	<navigation:Frame.UriMapper>
    		<uriMapper:UriMapper>
    			<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/Views/{pageName}.xaml"/>
    		</uriMapper:UriMapper>
    	</navigation:Frame.UriMapper>
    </navigation:Frame>
    NavigationService.Navigate(new Uri("/About", UriKind.Relative));
     
    Tuesday, March 23, 2010 8:20 AM
  • Your suggestion worked!  Thanks so much!

    Tuesday, March 23, 2010 8:39 AM
  • Isn't this a major bug - I was working with the example of the 

    Getting Started with Silverlight development http://timheuer.com/blog/articles/getting-started-with-silverlight-development.aspx

    which was done with silverlight 3 which works great and now this issue - which is kind of going backwards!!!!

    Friday, October 22, 2010 11:54 PM
  • Help:

    If I have no idea where to put the above xaml snippet.  I already have below.  Forget about the namespace change that I'm not sure of where ever I put the above I get a unexpected attribute

    Trying to get http://timheuer.com/blog/articles/getting-started-with-silverlight-development.aspx working in silverlight 4 in vb

    <navigation:Page x:Class="TwitterSearchMonitor1.Views.History"

     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

     xmlns:d

    ="http://schemas.microsoft.com/expression/blend/2008"

     xmlns:mc

    ="http://schemas.openxmlformats.org/markup-compatibility/2006"

     mc:Ignorable

    ="d"

     xmlns:navigation

    ="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"

     d:DesignWidth="640" d:DesignHeight

    ="480"

     Title

    ="History Page">

     <Grid x:Name

    ="LayoutRoot">

     <StackPanel

    >

     <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}"

     Text

    ="Search Term History"/>

     <ListBox x:Name="SearchTermHistory" SelectionChanged

    ="SearchTermHistory_SelectionChanged" />

     

    </StackPanel

    >

     </Grid

    >

    </

     navigation:Page

    >

     

     

    Saturday, October 23, 2010 12:14 AM
  • Still need help here

    getting Error 1 The tag 'UriMapper' does not exist in XML namespace 'clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation'. C:\testsilverlight\TwitterSearchMonitor1\TwitterSearchMonitor1\Views\History.xaml 12 14 TwitterSearchMonitor1

    Saturday, October 23, 2010 12:27 AM
  • Please tell us whats the version of silverlight you are using ?

    May be thats the problem.

    Saturday, October 23, 2010 2:01 AM
  • OK All The facts here

    1.  I am using visual studio 2010

    2.  Started with 

    Read Tim Heuer's 8-part blog series on getting started he has vb source for silverlight 3 which works:

    2.a.  System.Windows.Controls

    2.b. C:\Program Files (x86)\Microsoft SDKs\Silverlight\v3.0\Libraries\Client\System.Windows.Controls.dll

    2.c.. v2.0.50727

    3.  I took the same code and copied it into a project where the reference is pointing to silverlight 4

    3.a. System.Windows.Controls

    3.b. c:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\System.Windows.Controls.dll

    3.c. v2.0.50727

    4. The line of code that fails is:

     Me.NavigationService.Navigate(New Uri(String.Format("/Search/{0}", SearchTermHistory.SelectedItem.ToString()), UriKind.Relative))

    error message is can not find 

    5. if I remove the parameter  it works Me.NavigationService.Navigate(New Uri("/Search", UriKind.RelativeOrAbsolute))

    But I really need to be able to pass the parameters around.

    6. Below is the original xmal - no matter where I put the suggestion I get errors:

    <navigation:Page x:Class="TwitterSearchMonitor1.Views.History"
               xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
               xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
               xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
               xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
               mc:Ignorable="d"
               xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
               d:DesignWidth="640" d:DesignHeight="480"
               Title="History Page">
     

            <Grid x:Name="LayoutRoot">
           
            <StackPanel>
                <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}"
                               Text="Search Term History"/>
                <ListBox x:Name="SearchTermHistory" SelectionChanged="SearchTermHistory_SelectionChanged" />
              
            </StackPanel>
        </Grid>

    Saturday, October 23, 2010 11:20 AM
  • 2 factoids:

    a. notice the error message: Page not found: "/Search/russ""

    the end has 2 quotes?

    b. I did a hard coded test to make sure the listbox was not adding some strange characters

    Me.NavigationService.Navigate(New Uri("/Search/Tiger", UriKind.RelativeOrAbsolute))

    But that also failed the same way.

    So hopefully some one can show me the way to pass parameters between pages using silver light 4

    Thanks,

    Russ 

    Saturday, October 23, 2010 10:09 PM
  • NavigationService.Navigate(new Uri("/About", UriKind.Relative));


    This worked for me thanks so much.

    Friday, February 4, 2011 9:58 AM
  • I would use cookies. Thats how I do it.


     Dim cookie As String = "MyAppConnectionKey=" & "ILS"
            HtmlPage.Document.Cookies = Connection_Key


    You still need an import to system.windows.browser.

    You can make cookie a shared variable and use that to pass values back in forth.

    Friday, February 4, 2011 10:00 AM