0

Laurent BugnionのMVVM Lightテンプレートに基づいて新しいSLアプリケーションを作成しました。次に、/ Viewsディレクトリ(Home.xaml、TaskPlans.xaml、Tasks.xaml、およびTasks.xaml)にいくつかのナビゲーションページを作成しました。それらのページは空です - 私は各ページに単純なテキストブロックだけを作成しました。ティムHeuersテンプレートによると Tim HeuerナビゲーションフレームワークテンプレートとMVVM Lightの組み合わせ方法

は、ナビゲーションフレームワークを実現するために、私は
<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> 

/Views/MainPage.xaml

修正そしてここでメソッドの取り扱いhyperlingクリックです:私も/App.xamlを変更

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

#文字の後にアドレスバーの/Views/Home.xamlを非表示にし、MainPage.xamlの最初のハイパーリンクボタンのTag属性値を変更しました。私は、アプリケーションを実行し、「タスク」と「TaskPlans」ボタンをクリックし、ナビゲーションイベントを提供すると、すべてがo.k.

<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> 

を働いています「ホーム」のハイパーリンクボタンをクリックすると、「URIのコンテンツを読み込めません.URIが無効な可能性があります」というメッセージが表示され、iexplore.exeにシステム引数の例外が表示されます。

最初のハイパーリンクボタンのタグ内容を「/Views/Home.xaml」に戻すと、ナビゲーションが正常に動作します。

何とかタグ値を変更することはできますか?UrimapperがSL 5でどのように動作するのか違いはありますか?

アドバイスありがとうございます、ルドルフ。

答えて

1

は、彼がMVVMでナビゲートする方法について語っ本講演ではミックスで

を「ディープダイビングMVVMを」ローランの話をチェックしてください。彼

http://channel9.msdn.com/Events/MIX/MIX11/OPN03

+0

がsilverfighterありがとう...この話は実際にいくつかのadvanved MVVM技術のための良い時計ですナビゲーションサービス... を示唆して、あなたのリンクは私をたくさん助けました。 –

関連する問題