|
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.Linq;
using Microsoft.Practices.Prism.Regions;
using NavInfrastructure;
using NavModule_One.Models;
namespace NavModule_One.ViewModels
{
[Export]
[PartCreationPolicy(CreationPolicy.NonShared)]
public class CatalogViewModel : ViewModelBase, INavigationAware
{
#region Private Field
// Assing Cache - devlop EnterpriceLibrary
[Import]
protected CacheManager _cacheManager;
#endregion
#region .ctor
public CatalogViewModel()
{
// fire ctor in Base class.
// and assing GlobalCommand as CompositeCommand.
}
#endregion
#region Property CurrentItem
/// <summary>
/// Current base item.
/// </summary>
public EntityBase CurrentItem
{
get { return _currentItem; }
private set
{
if (value != _currentItem)
{
_currentItem = value;
this.RaisePropertyChanged("CurrentItem");
}
}
}
private EntityBase _currentItem;
#endregion
#region Property CatalogItems
private ObservableCollection<EntityBase> _catalogItems;
public ObservableCollection<EntityBase> CatalogItems //
{
get { return _catalogItems ?? (_catalogItems = new ObservableCollection<EntityBase>()); }
set
{
_catalogItems = value;
RaisePropertyChanged("CatalogItems");
}
}
#endregion
#region INavigationAware Members
public bool IsNavigationTarget(NavigationContext navigationContext)
{
// Only one view.
return true;
}
public void OnNavigatedFrom(NavigationContext navigationContext)
{
}
public void OnNavigatedTo(NavigationContext navigationContext)
{
var idEntity = int.Parse(navigationContext.Parameters["ParentId"]);
this.CurrentItem = _cacheManager.CacheDocuments.Single(i => i.IDEntity == idEntity);
PopulateViewModel();
}
#endregion
#region Help method
private void PopulateViewModel()
{
CatalogItems.Clear();
foreach (var i in _cacheManager.CacheDocuments.Where(i => i.Parent != null && i.Parent.IDEntity == _currentItem.IDEntity))
{
CatalogItems.Add(i);
}
}
#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.
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.