【问题标题】:Mvvm light toolkit and navigate by frameMvvm light 工具包和逐帧导航
【发布时间】:2010-07-15 15:25:52
【问题描述】:

你有解释 uri 导航的教程吗?当我的应用程序启动时,我在我的框架“Login.xaml”和他的 viewModel 中加载。当我单击“日志”按钮(我使用中继命令)时,我希望我的框架加载“Acceuil.xaml”。

如何制作?

谢谢

【问题讨论】:

    标签: silverlight-4.0 mvvm-light


    【解决方案1】:

    你太努力了。框架导航非常简单 - 只需创建框架,例如“MyFrame”,然后使用简单的 NavigateUri 值“/Acceuil.xaml”创建超链接。如果您想显示/隐藏视图模型的状态/详细信息中的链接,请使用您在视图模型中绑定和更新的属性。例如。您可以使用 UserInfo 属性,然后根据 UserInfo 属性为空值或类结果来显示/隐藏这样的转换器类:

    public class HideWhenNullConverter : IValueConverter
    {
    
        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            if (value == null)
            {
                return Visibility.Collapsed;
            }
            return Visibility.Visible;
        }
    
        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }
    }
    

    希望这可以帮助您入门。另一个技巧是向您的应用程序添加一些逻辑,以防止尝试导航到未经身份验证的位置。例如:

            private void mainFrame_Navigating(object sender, System.Windows.Navigation.NavigatingCancelEventArgs e)
        {
            List<string> anonUrls = new List<string>();
            anonUrls.Add("/Welcome");
            anonUrls.Add("/Register");
            anonUrls.Add("/ValidateEmail");
    
            var myAnonUrl = (from u in anonUrls
                            where e.Uri.OriginalString.StartsWith(u)
                            select u).Count();
    
            if ((WebContext.Current.User == null ||
                WebContext.Current.User.IsAuthenticated  == false) &&
                myAnonUrl == 0)
            {
                origUri = e.Uri;
                e.Cancel = true;
                mainFrame.Navigate(new Uri("/Welcome", UriKind.Relative));
            }
        }
    

    希望这有助于您进一步了解导航框架。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-31
      相关资源
      最近更新 更多