有没有人试过用VB实现ICommandSource? Microsoft提供的示例是在C#中,由于VB不允许隐式实现,因此这个界面在VB中无法实现!
答案 0 :(得分:1)
这取决于你想要实现它的类。如果您在自己的类(实现接口的地方)中引入了Command,CommandParameter和CommandTarget属性,则可以像任何其他接口一样实现它:
Public ReadOnly Property Command() As ICommand
Implements ICommandSource.Command
Get
' implementation goes here
End Get
End Property
顺便说一下,你仍然可以使用DP来实现:Implements指令在CLR属性上,不会干扰getter和setter的“不要触摸”实现。
如果要在其上实现它的类已经具有(继承)Command,CommandParameter和CommandTarget属性,并且您希望接口实现重用这些属性,则需要使用新名称创建新属性,将它们声明为接口实现并将它们备份到现有属性
Public ReadOnly Property ICommandSource_Command() As ICommand
Implements ICommandSource.Command
Get
Return Me.Command ' the existing implementation that can't be made implicit
End Get
End Property