jjzjj

viewmodels

全部标签

c# - 如何将这些 LINQ 结果加载到我的 ViewModel 类中?

我有一个LINQ查询,它返回与我的PictureGallery类匹配的结果。我需要将它们加载到我的ViewModel但我收到以下错误:Cannotimplicitlyconverttype'System.Linq.IQueryable'to'System.Collections.Generic.IEnumerable'.Anexplicitconversionexists(areyoumissingacast?)我是C#的新手。如何将“结果”转换到我的“PictureGallery”viewmddel类中?提前致谢!Controller://TestMediaIDvarMediaID=

c# - 将 ListView 的 SelectedItems 绑定(bind)到 ViewModel

我有一个ListView,它将项目与View模型中的属性绑定(bind)。在View模型中。ICollectionView_businessCollectionpublicICollectionViewBusinessCollection{get{return_businessCollection;}set{_businessCollection=value;RaisePropertyOnChange("BusinessCollection");}}如何在View模型中获取选中的businesscollection项? 最佳答案 1

c# - 如何在没有代码隐藏的情况下处理我的 ViewModel 中的 WPF 路由命令?

根据我对MVVM的理解,直接在ViewModel中处理路由命令是一种很好的做法。当路由命令在ViewModel中定义为RelayCommand(或DelegateCommand)时,很容易像这样直接绑定(bind)到命令:Command={BindingMyViewModelDefinedCommand}。实际上,对于在我的ViewModel外部定义的路由命令,我在View的代码隐藏中处理这些命令并将调用转发到ViewModel。但我觉得我不得不这样做很尴尬。它违背了推荐的MVVM良好实践。我认为应该有一种更优雅的方式来完成这项工作。如何直接在ViewModel中处理“System.W

c# - Caliburn.Micro 无法匹配来自不同程序集的 View 和 ViewModel

我刚开始使用Caliburn.Micro。我正在尝试引导我的简单示例解决方案,将ShellView(用户控件)放在Test.App程序集中,并将ShellViewModel放在Test.ViewModel程序集中。我得到的是一个带有以下文本的窗口:“找不到Caliburn.Test.ViewModel.ShellViewModel的View”。但如果我将ViewModel移动到.App程序集,它会完美运行。这是Caliburn.Micro.Test程序集(可执行)中的Bootstraper:namespaceCaliburn.Micro.Test{publicclassAppBoots

c# - SelectLists 属于 viewModels 吗?

看完这个问题ASP.NETMVC:NestingViewModelswithineachother,antipatternorno?和DerickBailey的评论ithinkthe"considerwhatyourviewmodelwouldlooklikeasxmlorjson"bitisprobablythemostimportantpoint,here.ioftenusethatperspectivetohelpmeunderstandwhattheviewmodelshouldlooklike,andtohelpmeunderstandwhatdatais"viewmodel

c# - 我能以某种方式告诉 Resharper ViewModel 的类型吗?

我们在不同的程序集中有Views和ViewModels。View的程序集具有对VM的引用。(有时我们需要隐藏代码)。ViewModel的DataContext是在代码中设置的,而不是在XAML中。因此,无论是VS还是Resharper都无法像智能感知那样提供帮助,Resharper也会给出很多警告。我们是否可以在XAML注释中为Resharper设置任何指令,以表明我们打算将View与特定类型的VM一起使用?更新:不错blogpost作为已接受答案的补充。 最佳答案 我遇到了同样的问题,并通过使用XAML中的设计时支持在XAML编辑

c# - Prism,将 Views 和 ViewModels 与 Unity 连接起来,试图理解它

CreatingtheViewandViewModelUsingUnityUsingUnityasyourdependencyinjectioncontainerissimilartousingMEF,andbothproperty-basedandconstructor-basedinjectionaresupported.Theprincipaldifferenceisthatthetypesaretypicallynotimplicitlydiscoveredatruntime;instead,theyhavetoberegisteredwiththecontainer.Typi

c# - XAML 中的命令绑定(bind)与 ViewModel 中的 ICommand 属性

我刚刚开始在应用程序中使用MVVM命令。我找到了许多示例,并在我的代码中尝试了两种方法。一些示例在xaml中具有命令绑定(bind),如下所示:...OpenRecentFile_Executed是ViewModel中的一个方法和一个静态ICommand,如下所示:publicstaticreadonlyICommandOpenRecentFile=newRoutedCommand("OpenRecent",typeof(MainWindow));我还看到ViewModel上有一个ICommand类型的属性在View中绑定(bind)到,如下所示:在ViewModel中:private

c# - WPF MVVM Light 单元测试 ViewModels

我不是MVVM模式的常客,这基本上是我第一次使用它。我过去所做的(“普通”WPF)是使用业务层和数据层(通常包含由服务或EntityFramework创建的实体)创建我的View。现在经过一番尝试后,我从MVVMLight创建了一个标准模板并执行了以下操作:定位器:publicclassViewModelLocator{staticViewModelLocator(){ServiceLocator.SetLocatorProvider(()=>SimpleIoc.Default);if(ViewModelBase.IsInDesignModeStatic){SimpleIoc.Defa

c# - 在使用 Automapper 映射 ViewModel 之后,我应该如何测试以及应该测试什么?

我正在尝试测试Controller的Index操作。该操作使用AutoMapper将域Customer对象映射到View模型TestCustomerForm。虽然这有效,但我关心的是测试我从Index操作收到的结果的最佳方法。Controller的索引操作如下所示:publicActionResultIndex(){TestCustomerFormcust=Mapper.Map(_repository.GetCustomerByLogin(CurrentUserLoginName));returnView(cust);}它的TestMethod看起来像这样:[TestMethod]pu