Navigation 如何将Tim Heuer导航框架模板与MVVM Light相结合
我基于Laurent Bugnon的MVVM Light模板创建了新的SL应用程序。然后,我在/Views目录中创建了几个导航页面-Home.xaml、TaskPlans.xaml、Tasks.xaml和Tasks.xaml。这些页面是空的——我只在每个页面中创建了简单的文本块 根据Tim Heuers实现导航框架的模板,我修改了/Views/MainPage.xamlNavigation 如何将Tim Heuer导航框架模板与MVVM Light相结合,navigation,mvvm-light,silverlight-5.0,navigation-framework,Navigation,Mvvm Light,Silverlight 5.0,Navigation Framework,我基于Laurent Bugnon的MVVM Light模板创建了新的SL应用程序。然后,我在/Views目录中创建了几个导航页面-Home.xaml、TaskPlans.xaml、Tasks.xaml和Tasks.xaml。这些页面是空的——我只在每个页面中创建了简单的文本块 根据Tim Heuers实现导航框架的模板,我修改了/Views/MainPage.xaml <UserControl x:Class="Valachy.Administration.Views.MainPage"
<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>
我还将/App.xaml更改为在地址栏中#字符后隐藏/Views/Home.xaml,并更改了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>
当我运行应用程序并提供导航事件时,单击“任务”和“任务计划”按钮,一切正常。如果单击“主页”超链接按钮,我将在iexplore.exe中收到系统参数异常,并显示消息“无法加载URI的内容。URI可能无效。”
当我将第一个超链接按钮的标记内容更改回“/Views/Home.xaml”时,导航工作正常
我是否可以以某种方式更改标记值,或者Urimapper在SL 5中的工作方式存在差异
谢谢你的建议,鲁道夫。看看Laurent在Mix“深海MVVM”上的演讲 在这次演讲中,他谈到了如何使用MVVM导航。他建议提供导航服务。。。 这篇演讲是对一些先进的MVVM技术的一次很好的观察
谢谢silverfighter,您的链接帮了我很多忙。
<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>