Published articles on other web sites*

Published articles on other web sites*
Mostrando entradas con la etiqueta MVVM. Mostrar todas las entradas
Mostrando entradas con la etiqueta MVVM. Mostrar todas las entradas

Binding Events to Methods in the Silverlight MVVM View Models

Introduction

This article introduces a simple method to bind UI events to the corresponding methods in the MVVM view models in Silverlight applications.

Background

In order to fully conform to the MVVM design pattern in Silverlight, we may want to move the event handling functions into the view models. Generally speaking, we have two types of UI components and two types of UI events in Silverlight applications.
  • UI controls like a Button have a property called Command. We can create a command property in the view model to handle the click event of the button by binding this command property in the view model to the button control's command property in the XAML. For detailed information about the command bindings, you can take a look at my recent article, "Data and Command Bindings for Silverlight MVVM Applications".
  • Unfortunately though, most of the UI events like "MouseEnter", "MouseLeave", and "SizeChanged", etc. do not have the corresponding Commands, we are unable to implement the ICommand interface to handle these events in the MVVM view models.
This article is to introduce a method to bind these events to the corresponding methods in the view models in Silverlight applications, so we can implement all the event handling functions in the view models, thus minimizing the code-behind files of the XAML views.
SolutionExplorer.JPG

Using the MVVM Pattern in Silverlight Applications

Using the MVVM Pattern in Silverlight Applications

By Microsoft Silverlight Team|December 1, 2010|Level 300 : Intermediate

Contents

Overview

Estimated Time: 45 minutes
The Model-View-ViewModel (MVVM) pattern provides a flexible way to build Silverlight applications that promotes code re-use, simplifies maintenance and supports testing. The pattern consists of three different components including the Model (entities and code on the server), the View (the Silverlight screens) and the ViewModel (the glue between the Model and the View). An example of the how the Model, View and ViewModel components relate to each other is shown next:

In this lab exercise you'll learn how to migrate an existing Silverlight application that uses