viewmodel

How to I connect a ViewModel to a View when the view model has parameters in the constructor?

江枫思渺然 提交于 2019-11-30 21:10:30
I'm using Prism and Unity to rewrite a WPF application using the MVVM pattern. Most of the Views are connected to the VM via the DataContext property, like so: <UserControl.DataContext> <VM:RibbonViewModel/> </UserControl.DataContext> The problem is that this method will not work when there is a parameter in the ViewModel's constructor. public RibbonViewModel(IEventAggregator eventAggregator) { this.eventAggregator = eventAggregator; } I get the error: Type 'RibbonViewModel' is not usable as an object element because it is not public or does not define a public parameterless constructor or a

ASP.Net MVC Update ViewModel on DropDown Selection changed

点点圈 提交于 2019-11-30 21:03:48
At first I'm absolutely new on web development. I'm trying to develop a Web application which consists of a single page (I started with an empty project trying to follow the mvc pattern). To populate my View I pass a ViewModel through my HomeController to my "Home"View. Now I want to change a few Label-Texts depending on a DropDown selection. ViewModel: public IEnumerable<Models.Language> AvailableLanguages; public Models.Language SelectedLanguage Public IEnumerable<Models.Text> Content; Language: public int ID; public string LanguageText; Text: public Language Language; public string

ContextMenu Command Binding to parent and to self

别来无恙 提交于 2019-11-30 20:53:48
问题 I am trying to create a ContextMenu on a DataGrid with multiple Command Bindings. Some have to be bound to the local ViewModel (i.e. the ViewModel of the Row) and some to the parents ViewModel. I had no luck so far following other solutions. I only get the SubCommand to execute. MainViewModel public class MainViewModel : ViewModelBase { public ObservableCollection<SubViewModel> Items { get; private set; } public MainViewModel() { Items = new ObservableCollection<SubViewModel>(); Items.Add(new

Is it a bad practice using model classes in controller in mvc?

喜欢而已 提交于 2019-11-30 20:50:56
I wanted to compare with best practices when working with an ORM or database tables in asp.net mvc. One of the major questions I have is should I instantiate the model classes directly in controller..not query the database but just use the model class to store the values. For e.g. If I am using entity framework as model...then is it a bad practice to use the entity class objects in the controller . There are times when it is just easier to directly use the database classes generated in the controller instead of creating ViewModels or even ViewData. We have a data access layer and a Business

How to handle `PartialRender` Models?

≯℡__Kan透↙ 提交于 2019-11-30 20:08:33
问题 if by any means I happen to have public class DoorsModel { public DoorsModel() { } public HttpPostedFileBase Image { get; set; } public String DoorLayout { get; set; } public bool ReplicateSettings { get; set; } public List<DoorDesignModel> Doors { get; set; } } public class DoorDesignModel { public DoorDesignModel() { } public HttpPostedFileBase FrontFile { get; set; } public HttpPostedFileBase BorderFile { get; set; } } and in my View I have a normal form to populate the Model Properties

How can I avoid command clutter in the ViewModel?

天涯浪子 提交于 2019-11-30 19:38:04
I am building an application that uses quite a few commands, and they are cluttering up my viewmodel. MVVM is new to me, so sorry if this question is a bit stupid. Is there a way to reduce the clutter? For example here you can see the a part of the clutter.. private void InitializeCommands() { LogoutCommand = new RelayCommand(Logout); OpenCommand = new RelayCommand(SetImage); SaveCommand = new RelayCommand(SaveImage, SaveImageCanExecute); UploadToFlickrCommand = new RelayCommand(UploadToFlickr); CropCommand = new RelayCommand(SetCropMouseEvents); RemoveRedEyeCommand = new RelayCommand

Updating a viewmodel from another viewmodel

青春壹個敷衍的年華 提交于 2019-11-30 19:33:29
I have two ViewModels one is attached to a main window and the other is attached to child window that is opened by clicking on a button on the main window. The child window contains a list of items and I want to select an item and display it in the main window by updating the main window viewmodel. What is the best way to accomplish this. Thanks! There are any number of ways to do this. Pass a reference to the main/parent view model into the child and have the child call the main view model. Have the child view model fire an event that the parent subscribes to. Use a messenger/mediator to

How do I ModelBind a many-to-many relationship with MVC 3 and Entity Framework Code First?

☆樱花仙子☆ 提交于 2019-11-30 18:32:37
问题 I'm coming across the same problem in my MVC 3 applications. I've got a view to create an new product and that product can be assigned to one or more categories. Here are my EF Code First Model Classes: public class Product { public int ProductID { get; set; } public string Name { get; set; } public virtual ICollection<Category> Categories { get; set; } } public class Category { public int CategoryID { get; set; } public string Name { get; set; } public virtual ICollection<Product> Products {

Create ViewModel for Navigation

谁都会走 提交于 2019-11-30 16:22:24
问题 I have an MVC 4 application with several views. I.e. Products, Recipes, Distrubutors & Stores. Each view is based around a model. Let's keep it simple and say that all my controllers pass a similar view-model that looks something like my Product action: public ActionResult Index() { return View(db.Ingredients.ToList()); } Ok so this is fine, no problems. But now that all of my pages work I want to change my navigation (which has dropdowns for each view) to load the items in that model. So I

TabControl disposes of controls on inactive tabs

不想你离开。 提交于 2019-11-30 14:33:08
问题 I'm using the MVVM pattern for my app. The MainWindow comprises a TabControl with the DataContext mapped to the ViewModel: <Window.Resources> <ResourceDictionary> <DataTemplate x:Key="templateMainTabControl"> <ContentPresenter Content="{Binding Path=DisplayName}" /> </DataTemplate> <local:ViewModel x:Key="VM" /> <local:WorkspaceSelector x:Key="WorkspaceSelector" /> <local:TabOneView x:Key="TabOneView" /> <local:TabTableView x:Key="TabTableView" /> <DataTemplate x:Key="TabOne"> <local