Silverlight 3 用户控件之间的导航?
我刚刚开始掌握来自 ASP.NET 和 Flex 的 silverlight 3。
我已按照此处的新导航教程进行操作,并仔细阅读了身份验证和角色管理教程也。
所以,我有一个主页,其中有一个框架、网格内部和几个视图。这些都是可导航的并且工作正常。我将此主页视为我想要的小应用程序的主页。
所以知道我想要一个login.xaml UserControl。这将处理所有登录,一旦经过身份验证,我想导航到主页,并使用其框架从那里开始。
我不想只是简单地将登录用作框架中的单独页面,因为我希望登录使用与应用程序其余部分不同的网格,并且也是独立的。
那么我如何从一个用户控件(登录)导航到另一个用户控件(主)?
我尝试过
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
//TO - DO: All the auth work, just want navigation sorted first
this.Visibility = Visibility.Collapsed;
App.Current.RootVisual = new MainPage();
}
但没有运气。我也尝试过初始化一个新的 main 并设置其可见性,但这当然不起作用。
我是否以正确的方式处理这个问题?
非常感谢。
编辑 - 好吧,进一步挖掘后,这个 看起来像是一种可以实现我所追求的方法,但它确实感觉有点黑客!这是 silverlight 3 的建议方式吗?再次感谢
Im just starting to get to grips with silverlight 3, coming from ASP.NET and Flex.
I have followed the new navigation tutorial here and read through the authentication and role management tutorials also.
So, i have a main page, which has a frame, inside of the grid, and several views. These are all navigatable and working fine. I see this main page as kind of a master page to my little application i have i mind.
So know I want to have a login.xaml UserControl. This will handle all login and once authenticated I want to navigate to the MainPage, and the use its frame to go from there.
I dont just want to simply use login as a seprate page within my frame as I want the login to use a different grid to the rest of the app, and also to be separate.
So how would I navigate from one user control (Login) to another (Main) ?
I have tried
private void btnLogin_Click(object sender, RoutedEventArgs e)
{
//TO - DO: All the auth work, just want navigation sorted first
this.Visibility = Visibility.Collapsed;
App.Current.RootVisual = new MainPage();
}
With no luck. Ive also tried just init'n a new main and setting its Visibility but this of course doesnt work.
Am I even approaching this in the correct way?
Thanks muchly.
Edit - Ok after digging a little further, this looks like an approach that will do what im after, but it does feel a little hackish! Is this the suggested way for siverlight 3? Thanks Again
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通常做的是创建一个 System.Windows.Controls.Navigation 类型的“MainPage.xaml”。它被分配给我的应用程序的 RootVisual 属性;除了导航框架之外,它几乎是空的:
然后我使用“rootFrame”导航框架来处理我所有的导航需求,例如,使用静态 NavigationManager 类中的这些方法:
所以在您的情况下,您可以像这样使用它:
或者:
What I've usually done is to create a "MainPage.xaml" which is of type System.Windows.Controls.Navigation. That gets assigned to the RootVisual property of my application; it's pretty much empty, except for a navigation frame:
Then I use the "rootFrame" navigation frame to handle all my navigation needs, e.g., with these methods from a static NavigationManager class:
So in your case, you might use it like:
Or:
SL3 中有 3 种类型的容器
不要交换用户控件,这是一个坏主意,它基本上意味着清除“MainPage”内容并添加新的用户控件。通过这样做,您将失去浏览器的后退/前进行为,因为 URL 永远不会改变,这不是导航框架的设计方式,您宁愿交换页面(视图)通过使用 NavigationService 来完成此操作。
现在 HomePage.xaml 是一个页面(不是 UserControl),在启动时,NavigationFrame 的默认加载页面应该是您的登录页面。
用户控件旨在成为可重用的功能,可以部署在多个页面上。
There are 3 types of containers in SL3
Do not swap UserControls, its a bad idea, it basically means clearing the "MainPage" content and Adding a new UserControl. By doing ths you lose the Back/Forth behavior of the browser since the URL never changes, thats not how the Navigation Framework was designed, you rather swap Pages (views) do this by using the NavigationService.
Now HomePage.xaml is a Page (not a UserControl), on Startup your default load page for the NavigationFrame should be your login page.
UserControls are meant to be re-usable functionality that can be deployed on multiple pages.