- vmwrapperexpress.zip
- VmWrapperExpress
- AppIcon
- VmWrapperExpress.ico
- Documentation
- Pending Issues.docx
- SetupVmWrapperExpress
- Debug
- Release
- setup.exe
- SetupVmWrapperExpress.msi
- SetupVmWrapperExpress.vdproj
- VmWrapperExpress.sln
- VmWrapperExpress
- App.xaml
- App.xaml.cs
- bin
- Debug
- Release
- Templates
- CollectionWrapper.cs.template
- ObjectWrapper.cs.template
- ViewModelBase.cs.template
- VmCollectionBase.cs.template
- VmObjectBase.cs.template
- VmWrapperExpress.exe
- VmWrapperExpress.pdb
- VmWrapperExpress.vshost.exe
- VmWrapperExpress.vshost.exe.manifest
- DomainModel
- obj
- Debug
- Release
- Properties
- Services
- Templates
- CollectionWrapper.cs.template
- ObjectWrapper.cs.template
- ReadMe.txt
- ViewModelBase.cs.template
- VmCollectionBase.cs.template
- VmObjectBase.cs.template
- Utility
- View
- ViewModel
- VmWrapperExpress.csproj
- VmWrapperExpress.csproj.user
- VmWrapperExpress.ico
- vmwrapperdemo.zip
- VmWrapperDemo
- _ReSharper.VmWrapperDemo
- CachesImage.bin
- ProjectModel
- ProjectModel.dat
- TodoCache
- WebsiteFileReferences
- .version
- WordIndex.New
- Xaml
- CacheProvider.dat
- VmWrapperDemo.4.5.resharper.user
- VmWrapperDemo.Domain
- VmWrapperDemo.sln
- VmWrapperDemo.ViewModel
- VmWrapperDemo
|
using System;
using System.Text;
using System.Windows;
using System.Windows.Input;
namespace VmWrapperDemo.ViewModel
{
public class ChangeCustomerNameCommand : ICommand
{
#region Fields
// Member variables
private MainWindowViewModel m_ViewModel;
#endregion
#region Constructor
public ChangeCustomerNameCommand(MainWindowViewModel viewModel)
{
m_ViewModel = viewModel;
}
#endregion
#region ICommand Members
/// <summary>
/// Whether this command can be executed.
/// </summary>
public bool CanExecute(object parameter)
{
return true;
}
/// <summary>
/// Fires when the CanExecute status of this command changes.
/// </summary>
public event EventHandler CanExecuteChanged
{
add { CommandManager.RequerySuggested += value; }
remove { CommandManager.RequerySuggested -= value; }
}
/// <summary>
/// Invokes this command to perform its intended task.
/// </summary>
public void Execute(object parameter)
{
// Set customer name
var customerNames = new string[]
{
"Sleepy Sonics", "Sneezy Snoozles",
"Dopey Dentists", "Doc Hopper's", "Happy Haven", "Bashful Manor",
"Grumpy Grocers"
};
var rnd = new Random();
var n = rnd.Next(0, 6);
var m = m_ViewModel.SelectedCustomer;
var currentCustomer = m_ViewModel.Customers[m];
var oldCustomerName = currentCustomer.Name;
currentCustomer.Name = customerNames[n];
// Show results in message box
var sb = new StringBuilder();
sb.Append(String.Format("Old customer name: {0}\r\n", oldCustomerName));
sb.Append(String.Format("New view model customer name: {0}\r\n", currentCustomer.Name));
sb.Append(String.Format("New domain model customer name: {0}\r\n", m_ViewModel.DomainCustomers[m].Name));
var message = sb.ToString();
var caption = "Customer Name Change";
var buttons = MessageBoxButton.OK;
var image = MessageBoxImage.Information;
var result = MessageBox.Show(message, caption, buttons, image);
}
#endregion
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
David Veeneman is a financial planner and software developer. He is the author of "The Fortune in Your Future" (McGraw-Hill 1998). His company, Foresight Systems, develops planning and financial software.