Question

J'ai créé de nouvelles applications SL basées sur MVVM Light Model par Laurent Bugnion. Ensuite, j'ai créé plusieurs pages de navigation dans / Views Directory - home.xaml, taskplans.xaml, Tâches.xaml et Tâches.xaml. Ces pages sont vides - j'ai créé uniquement un simple échantillon de texte dans chaque page.

Selon le modèle Tim Heuers pour implémenter le cadre de navigation, j'ai modifié /views/mainpage.xaml

<UserControl x:Class="Valachy.Administration.Views.MainPage"
         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"             
         xmlns:Helpers="clr-namespace:Valachy.Administration.Helpers" 
         xmlns:res="clr-namespace:Valachy.Administration.Resources"
         xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
         xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
         d:DesignWidth="640" d:DesignHeight="480"
         mc:Ignorable="d"             
         DataContext="{Binding Main, Source={StaticResource Locator}}">

<UserControl.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="../Skins/MainSkin.xaml" />
            <ResourceDictionary>
                <Helpers:ResourceWrapper x:Key="ResourceWrapper" />
                <Helpers:NotOperatorValueConverter x:Key="NotOperatorValueConverter" />
            </ResourceDictionary>
        </ResourceDictionary.MergedDictionaries>
    </ResourceDictionary>
</UserControl.Resources>

<Grid x:Name="LayoutRoot">
    <StackPanel Orientation="Horizontal" VerticalAlignment="Top">
        <StackPanel Orientation="Horizontal" Width="250">
            <HyperlinkButton Click="NavigateButtonClick" Tag="Home" Content="Home" FontFamily="24"></HyperlinkButton>
            <HyperlinkButton Click="NavigateButtonClick" Tag="/Views/Tasks.xaml" Content="Tasks" FontFamily="24"></HyperlinkButton>
            <HyperlinkButton Click="NavigateButtonClick" Tag="/Views/TaskPlans.xaml" Content="Plans" FontFamily="24"></HyperlinkButton>
        </StackPanel>
    </StackPanel>
    <navigation:Frame x:Name="MainFrame" HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" Margin="20" Source="/Views/Home.xaml"  />
</Grid>
</UserControl>

Et voici la méthode Manipulation Hyperling Cliquez:

private void NavigateButtonClick(object sender, System.Windows.RoutedEventArgs e)
    {
        HyperlinkButton hyperlinkButton = sender as HyperlinkButton;
        if (hyperlinkButton != null)
        {
            string urlString = hyperlinkButton.Tag.ToString();                
            Uri url = new Uri(urlString,UriKind.Relative);
            MainFrame.Navigate(url);
        }
    }

J'ai aussi changé /app.xaml sur masquer /views/home.xaml dans la barre d'adresse After # caractère et modification de la valeur d'attribut de balise dans le premier bouton d'hyperlien dans MAINPAGE.XAML.

<Application xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
         xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
         x:Class="Valachy.Administration.App"
         xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
         xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
         xmlns:vm="clr-namespace:Valachy.Administration.ViewModel"
         xmlns:navcore="clr-namespace:System.Windows.Navigation;assembly=System.Windows.Controls.Navigation"
         mc:Ignorable="d">
<Application.Resources>

    <!--Global View Model Locator-->
    <vm:ViewModelLocator x:Key="Locator"
                         d:IsDataSource="True" />
    <navcore:UriMapper x:Key="uriMapper">            
        <navcore:UriMapping Uri="Home" MappedUri="/Views/Home.xaml" />
        <navcore:UriMapping Uri="Tasks" MappedUri="/Views/Tasks.xaml" />
        <navcore:UriMapping Uri="TaskPlans" MappedUri="/Views/TaskPlans.xaml" />
    </navcore:UriMapper>
</Application.Resources>
</Application>

Lorsque je exécute une application et fournissez des événements de navigation Cliquez sur le bouton "Tâches" et "Taskplans", tout fonctionne O.K.K. Si je clique sur le bouton "Accueil" hyperlink, je reçois une exception d'argument système dans iexplore.exe avec message "Le contenu de l'URI ne peut pas être chargé. L'URI peut être invalide."

Lorsque je change de contenu d'étiquette du premier bouton d'hyperlien retour à "/views/home.xaml", la navigation fonctionne bien.

Puis-je modifier la valeur de la balise en quelque sorte ou il y a une différence comment Urimapper fonctionne dans SL 5?

Merci pour tout conseil, Rudolf.

Était-ce utile?

La solution

Découvrez la conversation de Laurent à Mix "Deep Dive Mvvm"

Dans ce discours, il parle de savoir comment naviguer avec MVVM.Il suggère un service de navigation ... Cette conversation est vraiment une bonne surveillance pour certaines techniques avantagées MVVM ...

http://channel9.msdn.com/events/mix/mix11/opn03

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top