Business Oriented Software Solutions or : "How to best compose processes & technologies to deliver fast time to market, feature and user oriented, high quality software solutions"
A common pattern for developping applications with SilverLight and WPF is the Model-View-ViewModel (MVVM) Design Pattern. The MVVP pattern is an evolution of the MVC and MVP well-known pattern, specially adapted to the advanced data binding features of WPF and SilverLight. Please refer to the following excellent MSDN article from Josh Smith for a complete description and implementation of the MVVM Pattern for WPF:
However, as stated in this article title, we're talking about an MVVM pattern for WPF. For those who have tried to develop portable applications working on both WPF and SilverLight, you know this frustration of discovering small differences between WPF and SilverLight and missing classes in SilverLight as compared to WPF.
And in our specific case, Josh defines a RelayCommand class, used to simplified the binding with user interface elements commands with underlying actions in the ViewModel class.
Here is the definition of the RelayCommand class:
public class RelayCommand : ICommand
{
#region Fields
readonly Action
This class makes use of the CommandManager object and the RequerySuggested event. When a user actions the UI in WPF, this triggers the CommandManager to requery all the commands. In Silverlight the CommandManager class does not exist: you have to do the work yourself!
So I created the following RelayCommand implementation, working for SilverLight:
public class RelayCommand : ICommand
{
#region Fields
readonly Action _execute;
readonly Predicate _canExecute;
///
/// In WPF we could use CommandManager. Does not work with SilverLight. Using this ICommandManager interface provides an alternative working for both SilverLight and WPF
///
readonly ICommandManager _commandManager;
#endregion // Fields
#region Constructors
///
/// Creates a new command that can always execute.
///
/// The execution logic.
public RelayCommand(Action execute, ICommandManager commandManager)
: this(execute, null, commandManager)
{
}
///
/// Creates a new command.
///
/// The execution logic.
/// The execution status logic.
public RelayCommand(Action execute, Predicate canExecute, ICommandManager commandManager)
{
if (execute == null)
throw new ArgumentNullException("execute");
_execute = execute;
_canExecute = canExecute;
_commandManager = commandManager;
}
#endregion // Constructors
#region ICommand Members
[DebuggerStepThrough]
public bool CanExecute(object parameter)
{
return _canExecute == null ? true : _canExecute(parameter);
}
public event EventHandler CanExecuteChanged
{
add { _commandManager.RequerySuggested += value; }
remove { _commandManager.RequerySuggested -= value; }
}
public void Execute(object parameter)
{
_execute(parameter);
}
#endregion // ICommand Members
}
}
And here is the definition of the ICommandManager interface:
public interface ICommandManager
{
event EventHandler RequerySuggested;
}
Now when creating a new command, you should pass a reference to an object implementing the ICommandManager interface. This object will usually be the ViewModel class itself. It is then the responsability of the ViewModel class to trigger the RequerySuggested event when anything in the state of the ViewModel changed that requires the command to be rebinded.
That's it, this completes the SilverLight implementation of the MVVM pattern.
I did attend the conference last year and I must say it was a real interesting time, meeting many people focused on the same ideas and concept than myself. Most of the people coming from the Java community I must say: not too much professionnals from the Microsoft side. Showing that the Java world still has the characteristic of a research & development environment with a step forward in this area, as compared to the Microsoft guys.
The conference is all about Model driven development, domain specific languages and code generation.
By the way the conference is located in Cambridge and I love the city! Makes the conference even more attractive!
I have just found out a GREAT new feature included in Windows 7 / Windows Server 2008 R2 :
Multiple monitor support for Remote Desktop Services allows users to open a Remote Desktop connection expanded across all the monitors on the client computer regardless of the client monitor configuration. With this feature, the user can fully utilize all the monitors connected to the client computer for the Remote Desktop connection thereby providing extra desktop space and an almost seamless experience with the client desktop that is much improved over “Span mode”.
I have been so frustated so far to not be able to fully take advantage of my two screens in remote scenarios. And it is more and more usual to work on virtual machines. For instance I develop with Visual Studio 2010 on a virtual Windows Server 2008 machine, and I was not able so far to fully utilize the multiple screens support of VS2010. I now can:)
The only thing to do to initiate a remote session with multiple screen support is to check the "Use all my monitors for the remote session" box:
WPF is great! I love it. Just so much more convenient and relevant to building user interfaces than Windows Forms!
However, unless you're using third parties components like Telerik, there is still a lack of controls. I recently had the need for a Split button: I button that shows a menu when clicked, to enable kind of a "multi-choices" button.
Here I found a nice and neat implementation of such a control:
Recent Comments