- MigrateToMvvmMef-Part3_Src.zip
- MigrateToMvvmMef-Part3_Src
- _Assemblies
- GalaSoft.MvvmLight.SL5.dll
- System.Windows.Interactivity.dll
- AnotherXap.Models
- AnotherXap.ViewModels
- AnotherXap.Views
- ProductApp.Common
- Bin
- Release
- Constants
- EventArguments
- Models
- ModuleServices
- obj
- ProductApp.Common.csproj
- ProductApp.Common.csproj.user
- Properties
- SaveState
- ProductApp.Main
- ProductApp.Models
- ProductApp.sln
- ProductApp.suo
- ProductApp.ViewModels
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
- MigrateToMvvmMef-Part1_Src.zip
- MigrateToMvvmMef-Part1_Src
- ProductApp.Common
- ProductApp.Main
- ProductApp.sln
- ProductApp.suo
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
- MigrateToMvvmMef-Part2_Src.zip
- MigrateToMvvmMef-Part2_Src
- _Assemblies
- GalaSoft.MvvmLight.SL5.dll
- System.Windows.Interactivity.dll
- ProductApp.Common
- Bin
- Release
- Constants
- EventArguments
- Models
- ModuleServices
- obj
- ProductApp.Common.csproj
- ProductApp.Common.csproj.user
- Properties
- ProductApp.Main
- ProductApp.Models
- ProductApp.sln
- ProductApp.suo
- ProductApp.ViewModels
- ProductApp.Views
- ProductApp.Web
- ProductRiaLib.Web
- ProductRiaLib
- Readme.txt
|
using System;
using System.Windows;
using System.Linq;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Collections.ObjectModel;
using ProductRiaLib.Web.Services;
using ProductRiaLib.Web.Models;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using ProductApp.Common;
namespace ProductApp.ViewModels
{
[Export(typeof(IModule)), ExportMetadata(MetadataKeys.Name, ModuleID.AddProductWindowViewModel)]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class AddProductWindowViewModel : ViewModelBase, IModule
{
// Constructor
public AddProductWindowViewModel()
{
Messenger.Default.Register(this, MessageToken.DataToAddProductVmMessage, new Action<Category>(OnDataToAddProductVmMessage));
}
private Category _selectedCategory;
//
public Category SelectedCategory
{
get { return _selectedCategory; }
set
{
if (!ReferenceEquals(_selectedCategory, value))
{
_selectedCategory = value;
RaisePropertyChanged("SelectedCategory");
}
}
}
private Product _addedProduct;
//-->
public Product AddedProduct
{
get { return _addedProduct; }
set
{
if (!ReferenceEquals(_addedProduct, value))
{
_addedProduct = value;
RaisePropertyChanged("AddedProduct");
}
}
}
private RelayCommand _okButtonCommand;
//
public RelayCommand OKButtonCommand
{
get
{
if (_okButtonCommand == null)
{
_okButtonCommand = new RelayCommand(
OnOKButtonCommand,
() => AddedProduct != null);
}
return _okButtonCommand;
}
}
//
private void OnOKButtonCommand()
{
try
{
if (AddedProduct != null)
{
AddedProduct.CategoryID = SelectedCategory.CategoryID;
Messenger.Default.Send(AddedProduct, MessageToken.DataToProductListVmMessage);
Messenger.Default.Send("OK", MessageToken.AddProductWindowMessage);
}
}
catch (Exception ex)
{
Messenger.Default.Send(ex, MessageToken.RaiseErrorMessage);
}
}
private RelayCommand _cancelButtonCommand;
//
public RelayCommand CancelButtonCommand
{
get
{
if (_cancelButtonCommand == null)
{
_cancelButtonCommand = new RelayCommand(
OnCancelButtonCommand,
() => true);
}
return _cancelButtonCommand;
}
}
//
private void OnCancelButtonCommand()
{
try
{
Messenger.Default.Send("Cancel", MessageToken.AddProductWindowMessage);
}
catch (Exception ex)
{
Messenger.Default.Send(ex, MessageToken.RaiseErrorMessage);
}
}
private void OnDataToAddProductVmMessage(Category selectedCategory)
{
SelectedCategory = selectedCategory;
AddedProduct = new Product();
}
}
}
|
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.
Shenwei is a software developer and architect, and has been working on business applications using Microsoft and Oracle technologies since 1996. He obtained Microsoft Certified Systems Engineer (MCSE) in 1998 and Microsoft Certified Solution Developer (MCSD) in 1999. He has experience in ASP.NET, C#, Visual Basic, Windows and Web Services, Silverlight, WPF, JavaScript/AJAX, HTML, SQL Server, and Oracle.