C# 需要知道如何创建DelegateCommand<;类型>;返回一个整数值
这就是我要做的。请密切注意InsertConlogEntry以及如何将其分配给DelegateCommand,但是,如何处理返回int 谢谢,C# 需要知道如何创建DelegateCommand<;类型>;返回一个整数值,c#,wpf,command,C#,Wpf,Command,这就是我要做的。请密切注意InsertConlogEntry以及如何将其分配给DelegateCommand,但是,如何处理返回int 谢谢, #region Members public static readonly string AddConlogEntry = "AddConlogEntry"; public static readonly string GetConlogList = "GetConlogList"; public stat
#region Members
public static readonly string AddConlogEntry = "AddConlogEntry";
public static readonly string GetConlogList = "GetConlogList";
public static readonly string GetConlogEntry = "GetConlogEntry";
public static readonly string Scope = "ConLog";
#endregion
#region Ctor
public ConLogCommands() :base()
{
scope = Scope;
DelegateCommand<ConlogEntryData> AddEntryCmd = new DelegateCommand<ConlogEntryData>("Add New Conlog Entry",
"AddConLogEntry", InsertConlogEntry);
this.Add(AddEntryCmd);
}
#endregion
#region Methods
private int InsertConlogEntry(ConlogEntryData data)
{
ConlogService service = new ConlogService();
return service.InsertConlogEntry(data.LoanNumber, data.UserId, data.Subject, data.Comment, data.EntryDate);
}
#地区成员
公共静态只读字符串AddConlogEntry=“AddConlogEntry”;
公共静态只读字符串GetConlogList=“GetConlogList”;
公共静态只读字符串GetConlogEntry=“GetConlogEntry”;
公共静态只读字符串Scope=“ConLog”;
#端区
#区域导体
public ConLogCommands():base()
{
范围=范围;
DelegateCommand AddEntryCmd=新的DelegateCommand(“添加新的Conlog条目”,
“AddConLogEntry”,插入目录);
添加(AddEntryCmd);
}
#端区
#区域方法
private int insertconloggentry(ConlogEntryData数据)
{
ConlogService=新的ConlogService();
return service.InsertConlogEntry(data.LoanNumber、data.UserId、data.Subject、data.Comment、data.EntryDate);
}
你不能。它只接受一个操作
,必须定义自己版本的DelegateCommand
,该命令接受一个Func
作为构造函数参数,而不是一个简单的操作
由于命令本身不关心返回值,因此可以按如下方式初始化它:
AddEntryCmd = new DelegateCommand<ConlogEntryData>("Add New Conlog Entry",
"AddConLogEntry", e => InsertConlogEntry(e));
AddEntryCmd=newdelegateCommand(“添加新的Conlog条目”,
“AddConLogEntry”,e=>InsertConlogEntry(e));
命令是动作,而不是功能。因此,它们不应该返回任何值
一个命令意味着一个响应某些输入而激发的动作。从技术上讲,逻辑应该是独立的
也就是说,如果只需要调用此方法并忽略结果,可以将其包装在操作中
并使用该操作生成委托命令:
Action<ConlogEntryData> action = c => this.InsertConlogEntry(c);
DelegateCommand<ConlogEntryData> AddEntryCmd = new DelegateCommand<ConlogEntryData>(
"Add New Conlog Entry","AddConLogEntry", action);
Action-Action=c=>this.InsertConlogEntry(c);
DelegateCommand AddEntryCmd=新的DelegateCommand(
“添加新的Conlog条目”、“添加CONLOGENTRY”操作);
谢谢大家,我通过ref传递一个数据结构解决了这个问题,该数据结构有一个字段,然后我用数据库插入返回的值(记录唯一id)填充该字段。我很感激你的回答。El Matador.谢谢大家,我通过ref传递了一个数据结构来解决这个问题,该数据结构有一个字段,然后我用数据库插入返回的值(记录唯一id)填充该字段。我很感激你的回答。El Matador谢谢大家,我通过ref传递一个数据结构来解决这个问题,该数据结构有一个字段,然后我用数据库插入返回的值(记录唯一id)填充该字段。我很感激你的回答。