ViewModelDiagram を公開します。
私のPPT置き場にViewModelDiagramという名前でj公開しています。
http://www.mnow.jp/tabid/220/Default.aspx
使い方。
1)MVVM Light Toolkit のプロジェクトを作成します。
2)出来上がったプロジェクトのViewModelフォルダに新しい項目 ViewModelDiagram を追加します。
Vmcd ファイルと tt ファイルが作成されます。
3)Vmcd ファイルを開いてツールバーの ViewModel を Drag & Drop します。
4)Aggregation をクリックして ViewModel の管理をする ViewModel間 で Drag & Drop します。
5)必要なプロパティを作成します。
6)保存後、ttファイルを右クリックしてカスタムツールの実行を選択します。
7)tt ファイルの下に ViewModel1.Generated.cs などの cs ファイルができます。
//------------------------------------------------------------------------------
// <auto-generated>
// このコードはツールによって生成されました。
// このファイルへの変更は、以下の状況下で不正な動作の原因になったり、
// コードが再生成されるときに損失したりします。
// </auto-generated>
//------------------------------------------------------------------------------
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using System.Linq;
namespace ViewModelDiagramSample.ViewModel
{
#pragma warning disable 1591
public partial class ViewModel1 : ViewModel1Base
{
}
public partial class ViewModel1Base : ViewModelBase, INotifyPropertyChanging, IDataErrorInfo
{
public ViewModel1Base()
{
InitializeCommand();
}
public ViewModel1Base(
int property1
)
{
_property1 = property1;
InitializeCommand();
}
public override void Cleanup()
{
base.Cleanup();
CleanupCommand();
CleanupViewModel();
}
private int _property1;
protected virtual void OnProperty1Updating(int value) {}
protected virtual void OnProperty1Updated() {}
protected virtual void OnProperty1Changing(int value) {}
protected virtual void OnProperty1Changed() {}
public int Property1
{
get
{
return _property1;
}
set
{
int oldValue = _property1;
OnProperty1Updating(value);
if (_property1 != value)
{
OnProperty1Changing(value);
OnPropertyChanging<int>("Property1", value, oldValue);
_property1 = value;
OnPropertyChanged<int>("Property1", value, oldValue);
OnProperty1Changed();
}
OnPropertyUpdated<int>("Property1", value, oldValue);
OnProperty1Updated();
}
}
public ViewModel2 ViewModel2 { get; set; }
public System.Collections.ObjectModel.ObservableCollection<ViewModel3> ViewModel3Collection { get; set; }
private void CleanupViewModel()
{
if (ViewModel2 != null)
{
ViewModel2.Cleanup();
ViewModel2 = null;
}
if (ViewModel3Collection != null)
{
foreach (var viewmodel in ViewModel3Collection)
{
viewmodel.Cleanup();
}
ViewModel3Collection.Clear();
ViewModel3Collection = null;
}
}
private RelayCommand _command1;
public RelayCommand Command1
{
get
{
return _command1;
}
}
protected virtual void OnCommand1Excec() {}
protected virtual bool CanCommand1Excec() { return true; }
private void InitializeCommand()
{
_command1 = new RelayCommand(OnCommand1Excec, CanCommand1Excec);
}
private void CleanupCommand()
{
_command1 = null;
}
public event EventHandler Event1;
protected void RaiseEvent1(EventArgs args)
{
if (Event1 != null)
{
Event1(this, args);
}
}
public event PropertyChangingEventHandler PropertyChanging;
[SuppressMessage("Microsoft.Design", "CA1030")]
protected virtual void RaisePropertyChanging<T>(string propertyName, T oldValue, T newValue, bool broadcast)
{
RaisePropertyChanging(propertyName);
if (broadcast)
{
Broadcast(oldValue, newValue, propertyName);
}
}
[SuppressMessage("Microsoft.Design", "CA1030")]
protected virtual void RaisePropertyChanging(string propertyName)
{
VerifyPropertyName(propertyName);
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
}
}
protected virtual void OnPropertyChanging<T>(string propertyName, T newValue, T oldValue)
{
RaisePropertyChanging<T>(propertyName, newValue, oldValue, false);
}
protected virtual void OnPropertyChanged<T>(string propertyName, T newValue, T oldValue)
{
RaisePropertyChanged<T>(propertyName, newValue, oldValue, false);
}
protected virtual void OnPropertyUpdated<T>(string propertyName, T newValue, T oldValue)
{
}
private Dictionary<string, string> _errors = new Dictionary<string, string>();
public virtual bool HasErrors
{
get { return (_errors.Count != 0 || Error != null); }
}
public virtual string this[string columnName]
{
get
{
return (_errors.ContainsKey(columnName) ? _errors[columnName] : null);
}
}
public virtual string Error
{
get { return null; }
}
public virtual Dictionary<string, string> Errors
{
get { return _errors; }
}
}
#pragma warning restore 1591
}
問題や要望があればこの記事にPOSTしてください。