【发布时间】:2015-03-16 12:26:17
【问题描述】:
我正在尝试为特定的 WPF 控件(Autodesk 的 Ribbontextbox - 基于 WPF 文本框)创建一个“原型”类,其中包括它自己的命令处理程序类。
RibbonTextBox 旨在将 ICommand 接口用于操作,而不是事件系统,这意味着它具有 Commandhandler 属性,我可以将命令分配给... 我的想法是创建一个基类,包括它自己的 Command-Class,所以在派生类中我只需要重写 execute 方法。
mustinherit class BaseClass
inherits RibbonTextBox
sub new()
me.Commandhandler= New CommandBase
end sub
public Class CommandBase
implements ICommand
Protected Overridable Function CanExecute(parameter As Object) As Boolean Implements System.Windows.Input.ICommand.CanExecute
Return Not parameter.value.ToString.IsEmptyStringOrNothing
End Function
Public Event CanExecuteChanged(sender As Object, e As System.EventArgs) Implements System.Windows.Input.ICommand.CanExecuteChanged
Protected Overridable Sub Execute(parameter As Object) Implements System.Windows.Input.ICommand.Execute
'This Method should be defined in the derived Instance!!!
End Sub
end class
我想如何使用它:
public Class DerivedClass
inherits BaseClass
public Overrides sub me.commandhandler.Execute() 'or some similar :-)
'here the definition of commandexecution
end sub
end Class
感谢任何提示! 谢谢, D
【问题讨论】:
-
我认为您必须使用事件/委托,您的 DerivedClass 必须处理 ExecuteEvent。另一种选择是拥有一个派生自 CommandBase 的 DerivedCommandClass,并将 DerivedClass 作为其构造函数的参数。
-
我很害怕 :-( 我想避免一些事件处理开销....
标签: .net vb.net inheritance