Wpf 无法在VB中实现ICommandSource

Wpf 无法在VB中实现ICommandSource,wpf,vb.net,xaml,routedcommand,Wpf,Vb.net,Xaml,Routedcommand,有人试过用VB实现ICommandSource吗? Microsoft提供的示例是C#,由于VB不允许隐式实现,因此该接口在VB中是不可实现的 这取决于要在哪个类上实现它。如果要在自己的类(实现接口的地方)中引入Command、CommandParameter和CommandTarget属性,则可以像其他接口一样实现它: Public ReadOnly Property Command() As ICommand Implements ICommandSource.Command Get

有人试过用VB实现ICommandSource吗? Microsoft提供的示例是C#,由于VB不允许隐式实现,因此该接口在VB中是不可实现的


这取决于要在哪个类上实现它。如果要在自己的类(实现接口的地方)中引入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的“donottouch”实现

如果要在其上实现的类已经(继承)了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

这就是我所做的,除了我做了implemetor属性private,因为不管怎么说,它是由DP公开的,如果我犯了错误请纠正我。不,我认为将其私有化是好的:正如你所说,出于绑定目的,它将使用DP,如果你不需要类外的CLR包装器属性,那么,把它公之于众是没有价值的。看看这个。所以你可能需要在c#中完成这项工作。