导航到另一页Ioc容器和MVVM指示灯 - c#

我正在使用MVVM light制作Windows通用10应用程序。

但是现在,如果我单击ShowWeatherPage上的项目,将导航到ShowWeatherDetailPage以获取有关所单击项目的更多详细信息。但是我不知道该怎么做。你能帮我做到这一点吗?

在下面可以找到我的代码。我使用IocContainers,并且每个页面都有一个viewmodel和仅命令绑定。

IocContainer公共类IocContainer
{
静态IocContainer()
{
SimpleIoc.Default.Register (false);
SimpleIoc.Default.Register (false);
SimpleIoc.Default.Register (false);
SimpleIoc.Default.Register (false);
SimpleIoc.Default.Register (false);
}

公共静态ShowWeatherPage ShowWeatherPage
{
获取{返回SimpleIoc.Default.GetInstance (); }
}

公共静态ShowWeatherViewModel ShowWeatherViewModel
{
获取{返回SimpleIoc.Default.GetInstance (); }
}

公共静态ApplicationViewModel ApplicationViewModel
{
获取{返回SimpleIoc.Default.GetInstance (); }
}

公共静态ShowWeatherDetailPage ShowWeatherDetailPage
{
获取{返回SimpleIoc.Default.GetInstance (); }
}

公共静态ShowWeatherDetailViewModel ShowWeatherDetailViewModel
{
获取{返回SimpleIoc.Default.GetInstance (); }
}
}

视图模型ApplicationViewModel公共类ApplicationViewModel:ViewModelBaseClass
{
私有页面_currentPage = IocContainer.ShowWeatherPage;

公共页面CurrentPage
{
得到
{
返回_currentPage;
}

{
如果(_currentPage!=值)
{
_currentPage =值;
OnPropertyChanged();
}
}
}

public void导航(页面页面,对象属性)
{
CurrentPage =页面;
}
}

ShowWeatherViewModel公共类ShowWeatherViewModel:ViewModelBaseClass
{
#region变量

private Item _selectedVillage = null;

#endregion变量

#region属性

公共项目选择村
{
得到
{
返回_selectedVillage;
}

{
如果(_selectedVillage!=值)
{
_selectedVillage =值;
ShowDetailPage();
}
}
}

#endregion属性

#region构造函数

公共ShowWeatherViewModel()
{}

#endregion构造函数

#region方法

私有void ShowDetailPage()
{
ApplicationViewModel appVm =新的ApplicationViewModel();
appVm.Navigate(IocContainer.ShowWeatherPage,SelectedVillage);
}

#endregion方法
}

ShowWeatherDetailViewModel公共类ShowWeatherDetailViewModel:ViewModelBaseClass
{}

ViewModelBaseClass公共类ViewModelBaseClass:INotifyPropertyChanged
{
公共事件PropertyChangedEventHandler PropertyChanged;

受保护的void OnPropertyChanged([CallerMemberName]字符串propertyName =“”)
{
如果(PropertyChanged!= null)
{
PropertyChanged(this,new PropertyChangedEventArgs(propertyName));
}
}
}

PagesMainPage <页面
x:Class =“ BALaboVoorbeeld.UWP.MainPage”
xmlns =“ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x =“ http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local =“ using:BALaboVoorbeeld.UWP”
xmlns:d =“ http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc =“ http://schemas.openxmlformats.org/markup-compatibility/2006”
DataContext =“ {Binding Source = {StaticResource ioc},Path = ApplicationViewModel}”
mc:Ignorable =“ d”>

ShowWeatherPage <页面
x:Class =“ BALaboVoorbeeld.UWP.Pages.ShowWeatherPage”
xmlns =“ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x =“ http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local =“ using:BALaboVoorbeeld.UWP.Pages”
xmlns:d =“ http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc =“ http://schemas.openxmlformats.org/markup-compatibility/2006”
DataContext =“ {Binding Source = {StaticResource ioc},Path = ShowWeatherViewModel}”
mc:Ignorable =“ d” Width =“ 450”>

<TextBlock Text =“乡村:”
Horizo​​ntalAlignment =“ Right” Margin =“ 4” VerticalAlignment =“ Center”
Grid.Row =“ 1” Grid.Column =“ 0” />

<Button Horizo​​ntalAlignment =“ Stretch” Margin =“ 4” VerticalAlignment =“ Center”
Grid.Row =“ 1” Grid.Column =“ 2” Command =“ {Binding ShowWeahter}”>

<ListBox Grid.Row =“ 2” Grid.Column =“ 0” Grid.ColumnSpan =“ 3”
ItemContainerStyle =“ {StaticResource lstidflt}”
SelectedItem =“ {Binding SelectedVillage,Mode = TwoWay}”
ItemTemplate =“ {StaticResource weatheritemdt}”
ItemsSource =“ {Binding VillageList}” />

ShowWeatherDetailPage <页面
x:Class =“ BALaboVoorbeeld.UWP.Pages.ShowWeatherDetailPage”
xmlns =“ http://schemas.microsoft.com/winfx/2006/xaml/presentation”
xmlns:x =“ http://schemas.microsoft.com/winfx/2006/xaml”
xmlns:local =“ using:BALaboVoorbeeld.UWP.Pages”
xmlns:d =“ http://schemas.microsoft.com/expression/blend/2008”
xmlns:mc =“ http://schemas.openxmlformats.org/markup-compatibility/2006”
mc:Ignorable =“ d”>

参考方案

您可以使用MVVM Light的导航服务导航到另一个视图。

http://www.mvvmlight.net/doc/nav1.cshtml

https://marcominerva.wordpress.com/2014/10/10/navigationservice-in-mvvm-light-v5/

“ new”语句之后的花括号有什么作用? - java

我在查看this example并想知道第一行的作用:private SiteStreamsListener listener = new SiteStreamsListener() { 看起来您可以以这种方式声明其他方法或重写方法。例如,我可以做以下事情吗?ArrayList myList = new ArrayList() { @Override Str…

“ finally”子句在异常处理中的好处 - java

作为对此的新手,在异常处理中使用finally子句有什么好处。换句话说,什么时候最好使用它,什么时候最好不要使用它。我唯一想到的就是关闭输入/输出流……还有其他好处? 参考方案 StinePike撰写的任何内容都很完美,但我想在其中添加一些内容。无论是否发生异常,都将执行finally块...。因此,我们可以通过在try块以及catch block()中写入…

“ c#运算符是否就像Java中的instanceof一样?” - c#

我刚刚发现了这个运算符,我想知道它是否可以安全使用。我的意思是,在Java中,我们的老师总是告诉我们要避免使用instanceof(),因为它会破坏多态性并经常显示不良的编码。提前。 c#参考方案 它是安全的'。至少使用此检查更为安全,而不仅仅是强制转换并假定类型!您可能更喜欢使用as运算符,该运算符将转换为所需的类型(如果适用),否则返回null。只记得检…

如何使HtmlGenericControl属性runat =“ server”。以从代码访问它? - c#

访问运行时创建的某些HtmlGenericControl时,我遇到一个奇怪的问题。如何制作HtmlGenericControl runat ="server"?以便我可以访问它 HtmlGenericControl myli = new HtmlGenericControl("li"); c#参考方案 正确,因为run…

使用准无服务器Web架构(“ AJAX模板魔术”)创建安全的“专用站点区域” - c#

首先,对不起,如果我的英语听起来不太好,我会尽量保持清晰。我打算开发一个具有以下架构的网站:提供给使用javascript模板和ajax加载内容的客户端的静态页面,该内容将通过ASP.NET MVC应用程序提供,该应用程序将json结果发送到客户端页面。我的问题很简单:我可以使用哪些方法为网站用户提供私有区域?我唯一想到的是提供一个登录页面,该页面将登录信息…