.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
david stephan
Gaurav Pal
Post New Web Links

Model View ViewModel question

Posted By:      Posted Date: October 23, 2010    Points: 0   Category :WPF


I´m playing around with XAML and MVVM, and have a question about the wiring between the model and the viewmodel:

If I have a model that updates its data on random times, what wiring is used between the model and the viewmodel to let the viewmodel know that the model has changed?.

Between the view and viewmodel a bindings and NotifyPropertyChanged would take care of this.


Trying to learn

View Complete Post

More Related Resource Links

Design Patterns: Problems and Solutions with Model-View-ViewModel


The Model-View-ViewModel (MVVM) design pattern describes a popular approach for building Windows Presentation Foundation or Microsoft Silverlight applications. Robert McCarter shows you how the ViewModel works, and discuss some benefits and issues involved in implementing a ViewModel in your code.

Robert McCarter

MSDN Magazine July 2010

Silverlight Patterns: Model-View-ViewModel In Silverlight 2 Apps


In this article, you'll learn how to avoid problematic tight coupling by applying the Model-View-ViewModel pattern in Silverlight 2.

Shawn Wildermuth

MSDN Magazine March 2009

Patterns: WPF Apps With The Model-View-ViewModel Design Pattern


In this article we explain just how simple it can be to build a WPF application the right way using the MVVM Pattern.

Josh Smith

MSDN Magazine February 2009

Another 'ViewModel closes the View' question...

Hi all, I'm somewhere in the middle of the learning curve that is the path to MVVM utopia!My question really concerns the ability to close a view from a view model.I don't want to be guilty of trying to force a solution to fit a pattern, but MVVM fits so well in all other areas there's just this one bit left to figure out.The project I'm working on is a system analagous to Microsoft Outlook.You have a main view (window) which has a list of things.These things could be messages or contacts in Outlook.From the main view you have the option to create a new thing or open an existing one.Regardless of which option you choose, a new view (window) opens to present you with a form for editing.From this point on, each new view that opens has the following options (relevant to my question)...1, Save.2, Close.3, Save & Close.Save is pretty straightforward, is just a property on the viewmodel which returns an ICommand (RelayCommand/DelegateCommand).Close is also pretty straightforward, that's just the cross in the top right hand corner of the window.Save & Close, however, is different. With option 2, the close is actually just a part of windows, we're not writing any code to do this.So how would I go about implementing option 3? Where the viewmodel first needs to persist the changes and then needs to close the view?Many thanks,MQCA

Fully Embracing the Model-View-ViewModel Pattern in WPF

I'm trying to get my head around the M-V-VM pattern as it is used with WPF. So far I have been successful in implementing this pattern but it's perfect (yet). There are a number of common UI workflows that I can't figure out how to implement in this pattern such as:1. A user clicks a button that should show a modal dialog box. Usually the VM has a command on it that the button is bound to and something executes. However, what needs to execute is a UI behavior (opening the dialog box). The VM should not open the dialog box (that would be wrong because the VM now has to know something about the UI). The Window or UserControl or Page inwhich the command was initiated should open the dialog box.2. A user clicks a button that executes a command on a VM. However, this is a long-running command and I'd like to show the WaitCursor during this operation. This is a UI function, not a VM function. Should the VM fire an event? And if so, how does the Xaml handle it?So, M-V-VM experts out there, what am I missing? Help me to see the light...Dave

MVVM Bind View Details to Model Via ViewModel when a Button clicked.


I have model called Car with prperties name,model,type,year.

I have implemeted the Viewmodel with same properties with OnpropertyChangedEvent including model object type Property.

I have a view usercontrol where textboxes for name, model and for year a combobox.

Whenever i fill the view i want to save those details into model via view model

I have written ICommand  Save which calls SaveCarDetails defined in viewmodel,  which is bind to a button in view ,All other texboxes text is bind to the properties of viewmodel properties.

When i put break point at ICommand SaveCommand and SaveCarDetails Function i could see the values filled from view.

But when i bind these details to another user control where listbox is placed and its itemsource property is set to Car property nothing but model object defined in the viewmodel.

I couldn't see the values binding via viewmodel to model.

Where as if i bind to textboxes in the listview i could see the values because i it's a dependency property.

Can any one please tell me what is the wrong i am doing here.




Model View Controller (MVC) for ASP.NET

Model View Controller (MVC) architectures, immediately wonder how the MVC pattern can be applied in an ASP.NET world. This article will demonstrate how the MVC pattern can be applied to an ASP.NET web application and still maintain the basic Microsoft supplied architecture.

Design Patterns: Model View Presenter


The MVP pattern helps you separate your logic and keep your UI layer free of clutter. This month learn how.

Jean-Paul Boodhoo

MSDN Magazine August 2006

Entity Data Model and database view returning the same columns as there are in a table


When adding a stored procedure into the Entity Data Model I can select whether the procedure returns a scalar, a (new) complex type or one of the entity types I already defined. 

How do I do something similar for a view?

I mean assuming I have a view like this

CREATE VIEW FilteredFoos as SELECT Foo.* FROM Foo join ... WHERE ...

(that is a view that implements some involved filtering, but returns all columns from one table) how do I add it to the project so that I can use the entity set, but get the Foo objects, not some new FilteredFoo objects.

var foos = myDB.FilteredFoos.Include("Bar").ToList();

foreach (Foo foo in foos) { ...

Thanks, Jenda

Executing Command Logic in a View Model

Through the use of the Windows Presentation Foundation's (WPF) advanced data-binding capabilities, the logical structure of a user interface can relatively easily be disconnected from its presentation. Bindable components can now contain nearly all of an application's user interface logic and in most circumstances, replace the need for controller objects from the classic Model-View-Controller (MVC) pattern. So it's no wonder that a new pattern for UI design has appeared

Model Display Property On View


How can I show display property of Model on View.


public class Model
        [DisplayName("First Name")]
        public string FirstName { get; set; }
        <div>FirstName</div><---Here I want to show Dispaly name
        <div><%= Html.Encode(Model.FirstName) %></div>

Mining Model - Business user's view

Using BIDS, when I create a Mining model solution I can see lot's of useful utilities like Mining Model viewer, Mining Model Prediction etc that comes with lot's of graphs' etc. What would be the best approach to display these graph's to business users. Can I do this easily using SSRS/PowerPivot etc..

The model of type could not be updated viewModel

Hello,  Ok i am pritty sure this is because I dont know how to handle sending back my viewmodel on edit:Error I am dealing with:here is my [HttpGet] public ActionResult Edit(int id) { ItemEditViewModel ItemEditVM = new ItemEditViewModel(); ItemEditVM.product = storedb.Products.Single(a => a.Product_Key == id); TempData["Error"] = ""; return View(ItemEditVM); } Form is nothing specials standard strongly typed using the view model [HttpPost] public ActionResult Edit(int id, FormCollection collection) { var product = storedb.Products.Single(a => a.Product_Key == id); try { UpdateModel(product, "product"); <--- Errors Here storedb.SaveChanges();//myview model i am usingpublic class ItemEditViewModel    {        public Product product {get; set;}    } Thanks  

Can you have a different input and output model in a view?

So here is what I would like to do. Lets say I have a view that can do multiple things, and thus talk to several different controllers. For example, it might create a new group, or change the name of an existing group, or add a user to some group. Now, for the view to display correctly, it would only need the username, a list of groups, and possibly a list of users. Yet for the controllers to work they would need a different set of information, the userid to be added to a group, the name of a new group, or the name and id of a group to edit.With this setup, there would be a potential of several different models for both input to the view, and output to the different controllers. I like the idea of using the helpers Html.Textboxfor() ect. to create the different submission elements, but I don't so much like the idea of having one giant model (Even if it just a model that inherits or has several sub models) that gets passed around everywhere for this view. It seems... clunky.Perhaps there is a better way to do this (if so, feel free to smacking me around with a few "Your and idiot"s) but is there any way to have a separate input and output model for a view?

General Controller to View logic question

Hello, I am currently learning the MVC2 Framework and I have a brief question in terms of my logic and if their are any flaws in it. I created a basic example in a couple of minutes that demonstrates the way I think about it. public ViewResult Index() { return View(); } public ViewResult Cookies() { return View(new Cookie()); } public ViewResult CookiesInput(Cookie cookie) { return View(cookie); }<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>I really like cookies</h2> Would you like a cookie? <% using (Html.BeginForm("Cookies", "Example")) { %> <p><input type="submit" value="Yes" /></p> <% } %> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server"> <h2>Cookies</h2> <% using (Html.BeginForm("CookiesInput", "Example")) { %> <%= Html.EditorForModel() %> <p><input type="submit" value="Gimme" /></p> <% } %> </asp:Content><asp:Content ID="Content2" ContentPlaceHolderID="MainConten

Noob Question - Using Linq in View

I just inherited an MVC2 application. So far my only experience with MVC is reading the Nerd Dinner sample chapter and downloading the nerd dinner app. I do plan to dive much deeper but i need a quick answer because i have to hit the ground running. So basically in the main Index view the view model is being passed as an IQueryable. Then he is doing some queries on the view model to loop through the data. See example below:<% if (Model.Where(w => w.State == workflowStep.Key).Count() > 0) { %>To me, even though minor, this is business logic and shouldn't be in the view. Shouldn't any type of logic like this be sorted out before you get to the view? Or is this common practice in MVC?Basically i want to know if I should spend time refactoring this thing or just go with the flow.  Thanks.

View Definition for SP 2010 Client Object Model

Hello, I am looking for where in the SP Client Object Model that I would find where the View Definitions are Located. For various reasons, I am displaying in my own custom listview a list of Documents and I would like these list results to share the same look as if the user was looking at the list in SharePoint.Please note this is NOT web based, but an application. Can someone give me a hint as to how to pull a view definition? Thanks, Andrew
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend