views:

73

answers:

1

Hello, Do you have a tutoriel which explain navigate with uri. When my application start i load in my frame "Login.xaml" and his viewModel. When i click on my button "Log" (i use a relaycommand) i want that my frame load "Acceuil.xaml".

how make it ?

thx

A: 

You are trying too hard. Frame navigation is very simple - just create your frame, such as 'MyFrame' then created Hyperlinks with a simple NavigateUri value of "/Acceuil.xaml". If you want to show/hide the links from the status / details of your view model, use a property which you bind to and update in the view model. For example. You can use a UserInfo property, then a converter class such as this to show / hide based upon the UserInfo property being a null value or a class result:

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();
    }
}

Hope this helps you get started. Another tip is to add some logic to your application to prevent attempts to navigate to unauthenticated locations. For example:

        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));
        }
    }

Hoepfully this helps you to understand the navigation frame a little more.

Ryan from Denver
Thank you for your response.
chris81