繁体   English   中英

内容框架导航不起作用-silverlight 4

[英]content frame navigation not working - silverlight 4

我是Silverlight的新手,现在面临着从一页到另一页的导航问题。 这是我的情况

我有一个名为page1.xaml的页面。 在此页面中,我放置了一个导航框架并在其中加载login.xaml页面。

现在,在按钮上单击(成功登录后),我需要移动到page2.xaml(这是另一种母版页),并且它还包含另一个框架,而且我需要首先在此页面中加载myaccount.xaml页。

现在,我到目前为止所做的是。 在app.xaml页面中,

private void Application_Startup(object sender, StartupEventArgs e) 
{
Panel grid = new Grid();
grid.Children.Add(new MasterSimple());
this.RootVisual = grid;       
}

上面的代码是因为,我想将根外观从page1.xaml更改为page2.xaml

现在在page1.xaml中,这是我的框架

<navigation:Frame x:Name="ContentFrame"  Style="{StaticResource ContentFrameStyle2}" 
                    Template="{StaticResource CustomTransitioningNavFrame}" Margin="0,8,0,0" Grid.Row="1" VerticalAlignment="Top" Height="270" Width="640">
<navigation:Frame.UriMapper>
<uriMapper:UriMapper>
<uriMapper:UriMapping Uri="/{pageName}" MappedUri="/{pageName}.xaml"/>
</uriMapper:UriMapper>
</navigation:Frame.UriMapper>
</navigation:Frame>

在page1.xaml构造函数上,

this.ContentFrame.Navigate(new Uri("/Loginnew", UriKind.Relative));

因此,上面的代码向我展示了我的page1.xaml页面,其中包含Loginnew.xaml。 很好 现在,在loginnew.xaml页面中,我有一个按钮,单击它需要导航到page2.xaml页面。 我在单击按钮时编写了以下代码

MasterTest2 currentPresentationPage = new MasterTest2();

(App.Current.RootVisual as Panel).Children.Clear();
(App.Current.RootVisual as Panel).Children.Add(currentPresentationPage);

在page2.xaml页面上,我有这个框架

<navigation:Frame x:Name="ContentFrame"  Style="{StaticResource ContentFrameStyle}"  
                           Navigating="ContentFrame_Navigating" Template="{StaticResource FrameControlTemplate1}">
</navigation:Frame>

在其构造函数上

 ContentFrame.Navigate(new Uri("/myaccount", UriKind.Relative));

这是我程序的结构。

现在我的问题是,当我单击登录页面按钮时,它显示了page2.xaml页面。 但是在page2.xaml页面中,它仅加载Loginnew.xaml页面,但不加载myaccount.xaml页面。 我还标记为,当我导航到page2.xaml时,地址栏中的URL更改为http://www.abc.com/test.aspx#Loginnew

这是为什么无法加载myaccount.xaml页的原因吗? 我应该怎么做才能将myaccount.xaml页面加载到page2.xaml的框架中?

this.ContentFrame.Navigate(new Uri("/Loginnew", UriKind.Relative));

我已经将上面的代码从构造函数移动到Frame的load事件,并且它开始工作。 :)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM