开发者

SL 3 navigation not working!

开发者 https://www.devze.com 2023-01-03 06:37 出处:网络
I converted all my existing Silverlight app UserControls to Pages so I could use the Navigation Framework.

I converted all my existing Silverlight app UserControls to Pages so I could use the Navigation Framework.

Anyway so I created a UserControl called MyFrame, which would host all the pages. In my App.xaml.cs I have the following to make sure that MyFrame is loaded when the App loads:

private void Application_Startup(object sender, StartupEventArgs e)
{
    this.RootVisual = new MyFrame();
}

My UriMapper class resides in App.xaml and looks like the following:

<navcore:UriMapper x:Key="uriMapper">
    <navcore:UriMapping Uri="Login" MappedUri="Login.xaml">
</navcore:UriMapper>

Within my 'MyFrame' class, I have the following

<StackPanel Orientation="Horizontal">
    <StackPanel Orientation="Vertical"开发者_高级运维>
        <HyperlinkButton Tag="Login" Content="Login" Click="HyperlinkButton_Click" />
    </StackPanel>
    <StackPanel Orientation="Vertical">
        <navigation:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}" />
     </StackPanel>
 </StackPanel>

And within the callback for my HyperlinkButton's event handler, I have the following:

private void HyperlinkButton_Click(object sender, RoutedEventArgs e)
{
    ContentFrame.Navigate(new Uri((sender as HyperlinkButton).Tag.ToString(), UriKind.Relative));
}

The Login.xaml file is in my root folder (right under Project). This navigation does not seem to work! The exception I get reads like so:

Navigation is only supported to relative URIs that are fragments, or begin with '/', or which contain ';component/'. Parameter name: uri

The Login page does not load. There is no problem with Login.xaml as when I set

this.RootVisual = new Login();

the page loads just fine.

I also tried setting the NavigateUri attribute of the HyperlinkButton to "Login." No cigar.

I'll appreciate any help!

Thanks a lot in advance


Okay turns out that explicitly setting the UriMapper property of the Frame resolves this issue. Looks like the UriMapper was not being initialized and associated with the Frame.

 <navigation:Frame x:Name="ContentFrame" Style="{StaticResource ContentFrameStyle}" UriMapper="{StaticResource uriMapper}"/>

The above solves the problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消