我在代码隐藏中定义了自定义控件:
Public Class MyControl
Inherits Button
Private _A As String
Private _B As String
Public Property A() As String
Get
Return A
End Get
Set(ByVal value As String)
_A = value
End Set
End Property
Public Property B() As String
Get
Return B
End Get
Set(ByVal value As String)
B = value
End Set
End Property
End Class
这是标记:
<ControlTemplate TargetType="{x:Type local:MyControl}">
<StackPanel>
<TextBlock Text="{Binding ?????}"/> <!-- A Property -->
<TextBlock Text="{Binding ?????}"/> <!-- B Property -->
</StackPanel>
</ControlTemplate>
我必须编写哪些代码来绑定这些属性?
答案 0 :(得分:2)
{Binding Path=A, RelativeSource={RelativeSource AncestorType={x:Type MyControl}}}