- 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;
using VmWrapperDemo.Domain;
namespace VmWrapperDemo.ViewModel
{
public class AddCustomerCommand : ICommand
{
#region Fields
// Member variables
private readonly MainWindowViewModel m_ViewModel;
#endregion
#region Constructor
public AddCustomerCommand(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)
{
// Create new customer
var newCustomer = new Customer("Moe Construction, Inc.", "Bill Moe");
newCustomer.Orders.Add(new Order(new DateTime(2009, 04, 04), 3000));
newCustomer.Orders.Add(new Order(new DateTime(2009, 04, 18), 2450));
// Add customer to the collection
var newWrapperObject = new CustomerVM(newCustomer);
m_ViewModel.Customers.Add(newWrapperObject);
// Show results in message box
var n = m_ViewModel.Customers.Count - 1;
var sb = new StringBuilder();
sb.Append(String.Format("New customer count: {0}\r\n", m_ViewModel.Customers.Count));
sb.Append(String.Format("New view model customer name: {0}\r\n", m_ViewModel.Customers[n].Name));
sb.Append(String.Format("New domain model customer name: {0}\r\n", m_ViewModel.DomainCustomers[n].Name));
var message = sb.ToString();
var caption = "Add Customer";
var buttons = MessageBoxButton.OK;
var image = MessageBoxImage.Information;
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.