IntroductionThis article introduces a simple method to bind UI events to the corresponding methods in the MVVM view models in Silverlight applications.BackgroundIn 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, so 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.
Read more: Codeproject
Unfortunately though, most of the UI events like "MouseEnter", "MouseLeave", and "SizeChanged", etc. do not have the corresponding Commands, so 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.
Read more: Codeproject
0 comments:
Post a Comment