2010-01-07 44 views

回答

1

這取決於你想實現它什麼課。如果你在介紹自己的類的命令,CommandParameter和CommandTarget屬性(你在哪裏實現接口),你可以實現它像任何其他接口:

Public ReadOnly Property Command() As ICommand 
    Implements ICommandSource.Command 
    Get 
    ' implementation goes here 
    End Get 
End Property 

您仍然可以使用一個DP爲順便說一句,實現,實現指令是在CLR屬性上,不會干涉getters和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 
+0

這就是我所做的,除了我實現了私有屬性,因爲它由DP公開,因此如果我犯了錯誤,請糾正我。 – Shimmy

+0

不,我認爲它是私人的很好:正如你所說,爲了約束的目的,它將使用DP,並且如果你不需要類之外的CLR包裝器屬性,那麼將它公開是沒有價值的。 – itowlson

+0

你搖滾,你也有我的投票! – Shimmy