silverlight – 如何导航一个xaml页面到另一个?

silverlight – 如何导航一个xaml页面到另一个?,第1张

概述我有2页我需要导航mainpage.xaml到login.page xaml,但它会抛出我 你调用的对象是空的.在Root.Children.Clear(); …. 我将这段代码添加到App.xaml中: private void Application_Startup(object sender, StartupEventArgs e) { Grid my 我有2页我需要导航mainpage.xaml到login.page xaml,但它会抛出我
你调用的对象是空的.在Root.Children.Clear(); ….

我将这段代码添加到App.xaml中:

private voID Application_Startup(object sender,StartupEventArgs e)        {            GrID myGrID = new GrID();            myGrID.Children.Add(new MainPage());            this.RootVisual = myGrID;       }

而不是在main.xaml上添加一些代码来导航到LoginUI.xaml

namespace Gen.CallCenter.UI{    public partial class MainPage : UserControl    {        public MainPage()        {            InitializeComponent();            GrID Root = ((GrID)(this.Parent));            Root.Children.Clear();            Root.Children.Add(new LoginUI());        }    }}

我如何将main.xaml导航到LoginUI.xaml?

解决方法 像 AnthonyWJones说你需要使用导航框架.

首先,您需要在您的项目中添加System.windows.Controls.Navigation的引用,并在其中引用它MainPage.xaml

xmlns:navigation="clr-namespace:System.windows.Controls;assembly=System.windows.Controls.Navigation"

那么您将需要一个框架,您可以在其中切换不同的XAML页面.这样的事情

<navigation:Frame x:name="navFrame" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Source=”/VIEws/First.xaml” />

现在在MainPage.xaml的某个地方,你可以有一个带有标签的按钮

< button Click =“button_Click”Tag =“/ VIEws / Second.xaml”Content =“Second”/>

在button_Click事件处理程序中,您可以切换navFrame中显示的内容.

private voID button_Click(object sender,RoutedEventArgs e){    button thebutton = sender as button;    string url = thebutton.Tag.ToString();    this.navFrame.Navigate(new Uri(url,UriKind.relative));}

需要注意的是,通过使用NavigationFramework,浏览器后退按钮和前进按钮功能完美,地址栏中的URL会根据您当前使用的XAML页面进行更新.

总结

以上是内存溢出为你收集整理的silverlight – 如何导航一个xaml页面到另一个?全部内容,希望文章能够帮你解决silverlight – 如何导航一个xaml页面到另一个?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1002044.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-22
下一篇 2022-05-22

发表评论

登录后才能评论

评论列表(0条)

保存