mirror of
https://gitee.com/akwkevin/aistudio.-wpf.-diagram
synced 2026-03-03 00:00:57 +08:00
141 lines
4.1 KiB
C#
141 lines
4.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Input;
|
|
|
|
namespace AIStudio.Wpf.DiagramDesigner
|
|
{
|
|
public class BlockDiagramViewModel : DiagramViewModel, IBlockDiagramViewModel
|
|
{
|
|
public BlockDiagramViewModel()
|
|
{
|
|
}
|
|
|
|
#region
|
|
private ICommand _addNextCommand;
|
|
public ICommand AddNextCommand
|
|
{
|
|
get
|
|
{
|
|
return this._addNextCommand ?? (this._addNextCommand = new SimpleCommand(ExecuteEnable, this.ExecutedAddNextCommand));
|
|
}
|
|
}
|
|
|
|
private ICommand _removeNextCommand;
|
|
public ICommand RemoveNextCommand
|
|
{
|
|
get
|
|
{
|
|
return this._removeNextCommand ?? (this._removeNextCommand = new SimpleCommand(ExecuteEnable, this.ExecutedRemoveNextCommand));
|
|
}
|
|
}
|
|
|
|
private ICommand _addChildCommand;
|
|
public ICommand AddChildCommand
|
|
{
|
|
get
|
|
{
|
|
return this._addChildCommand ?? (this._addChildCommand = new SimpleCommand(ExecuteEnable, this.ExecutedAddChildCommand));
|
|
}
|
|
}
|
|
|
|
private ICommand _removeChildCommand;
|
|
public ICommand RemoveChildCommand
|
|
{
|
|
get
|
|
{
|
|
return this._removeChildCommand ?? (this._removeChildCommand = new SimpleCommand(ExecuteEnable, this.ExecutedRemoveChildCommand));
|
|
}
|
|
}
|
|
#endregion
|
|
|
|
#region Block使用
|
|
private void ExecutedAddNextCommand(object parameter)
|
|
{
|
|
if (parameter is BlockNextPara blockItemPara)
|
|
{
|
|
DoCommandManager.DoNewCommand(this.ToString(),
|
|
() => {
|
|
blockItemPara.Item.AddNext(blockItemPara.Next);
|
|
},
|
|
() => {
|
|
blockItemPara.Item.RemoveNext();
|
|
});
|
|
}
|
|
}
|
|
|
|
private void ExecutedRemoveNextCommand(object parameter)
|
|
{
|
|
if (parameter is BlockNextPara blockItemPara)
|
|
{
|
|
DoCommandManager.DoNewCommand(this.ToString(),
|
|
() => {
|
|
blockItemPara.Item.RemoveNext();
|
|
},
|
|
() => {
|
|
blockItemPara.Item.AddNext(blockItemPara.Next);
|
|
});
|
|
}
|
|
}
|
|
|
|
private void ExecutedAddChildCommand(object parameter)
|
|
{
|
|
if (parameter is BlockContainerPara blockContainerPara)
|
|
{
|
|
DoCommandManager.DoNewCommand(this.ToString(),
|
|
() => {
|
|
blockContainerPara.Item.AddChild(blockContainerPara.Child, blockContainerPara.Container);
|
|
},
|
|
() => {
|
|
blockContainerPara.Item.RemoveChild(blockContainerPara.Child, blockContainerPara.Container);
|
|
});
|
|
}
|
|
}
|
|
private void ExecutedRemoveChildCommand(object parameter)
|
|
{
|
|
if (parameter is BlockContainerPara blockContainerPara)
|
|
{
|
|
DoCommandManager.DoNewCommand(this.ToString(),
|
|
() => {
|
|
blockContainerPara.Item.RemoveChild(blockContainerPara.Child, blockContainerPara.Container);
|
|
},
|
|
() => {
|
|
blockContainerPara.Item.AddChild(blockContainerPara.Child, blockContainerPara.Container);
|
|
});
|
|
}
|
|
}
|
|
#endregion
|
|
}
|
|
|
|
public class BlockNextPara
|
|
{
|
|
public BlockDesignerItemViewModel Item
|
|
{
|
|
get; set;
|
|
}
|
|
public BlockDesignerItemViewModel Next
|
|
{
|
|
get;set;
|
|
}
|
|
}
|
|
|
|
public class BlockContainerPara
|
|
{
|
|
public BlockDesignerItemViewModel Item
|
|
{
|
|
get; set;
|
|
}
|
|
public BlockDesignerItemViewModel Child
|
|
{
|
|
get; set;
|
|
}
|
|
public BlockItemsContainerInfo Container
|
|
{
|
|
get; set;
|
|
}
|
|
}
|
|
}
|