viewmodel

How can I open another view in WPF MVVM using click handlers and commands? (Is my solution reasonable?)

倖福魔咒の 提交于 2019-12-18 07:19:12
问题 I am writing a WPF application that has two windows. I have a MainWindowViewModel that holds two more view models: AllTagsViewModel and PlotViewModel . public AllTagsViewModel AllTagsViewModel { get; private set; } public PlotViewModel PlotViewModel { get; private set; } At the moment, I'm using this solution as a click handler in the main window: private void LaunchPlotWindow_OnClick(object sender, RoutedEventArgs e) { if (PlotWindow.GlobalInstanceCount == 0) { PlotWindow plotWindow = new

How do I update the parent viewmodel when child viewmodel is updated

杀马特。学长 韩版系。学妹 提交于 2019-12-18 05:22:47
问题 In my first view model (renamed to MainViewModel) I have a list of ActionViewModels. In my xaml i have a listbox which is bound to the list, in the listbox i have a template which binds to properties from the ActionViewModel. So far so good and everything works. When selecting one of the listitems i navigate to an ActionViewModel and pass the id with it. The ActionViewModel retrieves information from a static list in memory from which the MainViewModel also retrieved the information to create

Binding property with parent ViewModel

假如想象 提交于 2019-12-18 05:08:38
问题 Please refer to How can I tell my DataTemplate to bind to a property in the PARENT ViewModel? I have similar problem... But this solution didn't work for me. I have a MainViewModel which has an observable collection of another view model say View1/ViewModel1. This view has a tree control and I need context menu for the tree. My main view has a menu. Those main menu and context menu are connected. So how can I bind the context menu commands to the main viewmodel's properties? 回答1: Basically,

Constructor injection of a View Model instance used as an Action method parameter

百般思念 提交于 2019-12-18 04:52:47
问题 When a view model is created you can populate the options (e.g. used in a dropdown list) into a setter property of the view model. The problem is that when that view model is later passed as a parameter (by the framework!) into an action method, those property values has not become automagically repopulated, so if you need to redisplay the form because of validation errors, you need to repopulate those options again. One potential solution, which I am asking for specifically in this question,

Why a viewmodel factory is needed in Android?

寵の児 提交于 2019-12-18 03:59:11
问题 We have been discussing about this but we don't know the reason of creating a viewmodel factory to create a viewmodel instead of instantiate the viewmodel directly. What is the gain of creating a factory that just creates the viewmodel? I just put a simple example of how I did it without Factory here is the kodein module: val heroesRepositoryModel = Kodein { bind<HeroesRepository>() with singleton { HeroesRepository() } bind<ApiDataSource>() with singleton { DataModule.create() } bind

MVVM and collections of VMs

左心房为你撑大大i 提交于 2019-12-17 23:29:09
问题 A common senario: A model with a collection of item models. E.g a House with a collection of People. How to structure this correctly for MVVM - particulary with regard to updating the Model and ViewModel collections with additions and deletes? Model House contains a collection of model People (normally a List<People> ). View model HouseVM contains the House object that it wraps and an ObservableCollection of view model PeopleVM ( ObservableCollection<PeopleVM> ). Note that we end up here with

WPF: how to signal an event from ViewModel to View without code in codebehind? [duplicate]

℡╲_俬逩灬. 提交于 2019-12-17 21:55:21
问题 This question already has answers here : How can I Have a WPF EventTrigger on a View trigger when the underlying Viewmodel dictates it should? (4 answers) Closed 5 years ago . I have quite simple (I hope :)) problem: In MVVM, View usually listens on changes of ViewModel's properties. However, I would sometimes like to listen on event, so that, for example, View could start animation, or close window, when VM signals. Doing it via bool property with NotifyPropertyChanged (and starting

How to use ViewModels in ASP.NET MVC?

我是研究僧i 提交于 2019-12-17 18:58:03
问题 I just started learning about ViewModels in ASP.NET MVC. So, I thought of implementing a sample example as below: Business Entity public class AddModel { public int a { get; set; } public int b { get; set; } public int Add() { return (this.a + this.b); } } Add ViewModel public class AddViewModel { public AddModel addModel; public int Total { get; set; } } Controller public class AddController : Controller { [HttpPost] public JsonResult Add(AddViewModel model) { int iSum = model.addModel.a +

How to use ViewModels in ASP.NET MVC?

守給你的承諾、 提交于 2019-12-17 18:57:10
问题 I just started learning about ViewModels in ASP.NET MVC. So, I thought of implementing a sample example as below: Business Entity public class AddModel { public int a { get; set; } public int b { get; set; } public int Add() { return (this.a + this.b); } } Add ViewModel public class AddViewModel { public AddModel addModel; public int Total { get; set; } } Controller public class AddController : Controller { [HttpPost] public JsonResult Add(AddViewModel model) { int iSum = model.addModel.a +

Ignore mapping one property with Automapper

我的未来我决定 提交于 2019-12-17 16:43:18
问题 I'm using Automapper and I have the following scenario: Class OrderModel has a property called 'ProductName' that isn't in the database. So when I try to do the mapping with: Mapper.CreateMap<OrderModel, Orders>(); It generates an exception : "The following 1 properties on Project.ViewModels.OrderModel are not mapped: 'ProductName' I've read at AutoMapper's Wiki for Projections the opposite case (the extra attribute is on the destination, not in the source which is actually my case ) How can