This is the continuation from Part 1 where I walked through creating my Model. The next step is to create a View and a View Model. There should only be one View Model per View. I will try to take advantage of xaml binding where possible.
Following is my View Model.
Review the comments in the code snippet for explanation. The goal is to place all the logic specific to UI in the View Model. The View Model should not be accessing any controls directly. The View knows about the View Model, but the View Model does not have a reference back to the View. The View Model basically bridges the gap between the View and the Model.
The View code behind will access controls in a case where direct binding is not available, but any logic should still be placed in the View Model. The View code behind will generaly handle events and make calls to the View Model. I will cover that in Part 3 of the post.
Over last few days I’ve been working with the Telerik GridView control in a Silverligt 3 project. The goal was to implement an editable grid using MVVM (Model-View-View Model) pattern. A user must be able to Add/Edit/Delete rows from the grid.
I will be using the Telekik controls version 2009.3.1208.1030
I will start by creating my Model.
I added validation directly to my model for the First Name and Last Name using Attributes. I also implemented System.ComponentModel.INotifyPropertyChanged to notify my view when a property changes.
In Part 2 of the post I will go through creating a View Model.
I recently had to upgrade an ASP .net 1.1 solution to .net 3.5. The website had a form where a user had an option to upload a file.
The ‘File Name’ is a read only textbox.
- <asp:TextBox runat="server" ID="txtFileName" ReadOnly="true" />
To get around this issue, remove the ReadOnly attribute from the textbox and add the readonly attribute in code.
- txtFileName.Attributes.Add("readonly", "readonly")