2010-07-15 39 views
0

你有一個tutoriel解釋與uri導航。當我的應用程序開始加載我的框架「Login.xaml」和他的viewModel。當我點擊我的按鈕「日誌」(我使用relaycommand)我想我的幀加載「Acceuil.xaml」。Mvvm光工具包,並通過框架導航

怎麼了?

thx

回答

0

您正在努力工作。框架導航非常簡單 - 只需創建您的框架(如「MyFrame」),然後使用簡單的NavigateUri值「/Acceuil.xaml」創建超鏈接。如果要顯示/隱藏視圖模型狀態/細節的鏈接,請使用您在視圖模型中綁定並更新的屬性。例如。您可以使用的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)); 
     } 
    } 

大概這可以幫助您更多地瞭解導航框架。

+0

感謝您的回覆。 – chris81 2010-07-20 06:20:31