У меня есть класс VM, который используется для подключения представления к моей модели данных сущности ADO.NET с использованием класса P_BUDGET.Это отлично работает, получает мои данные, делает все красиво.У меня около 15-20 страниц, которые будут основаны на той же структуре, что и эта, и код будет практически идентичен, за исключением EntityType (P_BUDGET, P_ACCOUNT, P_CIRCUIT и т. Д. И т. Д.).Я чувствую, что должен быть способ абстрагироваться от этого, но я попытался и потерпел неудачу с треском!Я также чувствую, что должен иметь возможность использовать одно представление, одну модель представления и просто поменять сущности, привязанные к GV ... Я просто не смог найти способ вариации типа, который пронизывает всю модель представления.
Ценю вашу помощь,
Скотт
public class TestViewModel : ViewModelBase
{
private readonly ODADomainContext _context = new ODADomainContext();
private readonly DomainCollectionView<P_BUDGET> _view;
private readonly DomainCollectionViewLoader<P_BUDGET> _loader;
private readonly EntityList<P_BUDGET> _source;
private bool _isGridEnabled;
/// <summary>
/// Initializes a new instance of the TestViewModel class.
/// </summary>
public TestViewModel()
{
this._source = new EntityList<P_BUDGET>(this._context.P_BUDGETs);
this._loader = new DomainCollectionViewLoader<P_BUDGET>(
this.LoadSampleEntities,
this.OnLoadSampleEntitiesCompleted);
this._view = new DomainCollectionView<P_BUDGET>(this._loader, this._source);
INotifyCollectionChanged notifyingSortDescriptions =
(INotifyCollectionChanged)this.CollectionView.SortDescriptions;
notifyingSortDescriptions.CollectionChanged +=
(sender, e) => this._view.MoveToFirstPage();
using (this.CollectionView.DeferRefresh())
{
this._view.PageSize = 10;
this._view.MoveToFirstPage();
}
}
#region View Properties
public bool IsGridEnabled
{
get
{
return this._isGridEnabled;
}
private set
{
if (this._isGridEnabled != value)
{
this._isGridEnabled = value;
this.RaisePropertyChanged("IsGridEnabled");
}
}
}
public ICollectionView CollectionView
{
get { return this._view; }
}
#endregion
private LoadOperation<P_BUDGET> LoadSampleEntities()
{
this.IsGridEnabled = false;
return this._context.Load(
this._context.GetBudgetsQuery());
}
private void OnLoadSampleEntitiesCompleted(LoadOperation<P_BUDGET> op)
{
this.IsGridEnabled = true;
if (op.HasError)
{
// TODO: handle errors
_view.PageSize = 0;
op.MarkErrorAsHandled();
}
else if (!op.IsCanceled)
{
this._source.Source = op.Entities;
_view.PageSize = 10;
this._view.MoveToFirstPage();
if (op.TotalEntityCount != -1)
{
this._view.SetTotalItemCount(op.TotalEntityCount);
}
}
}
////public override void Cleanup()
////{
//// // Clean own resources if needed
//// base.Cleanup();
////}
}