绑定到后面的代码中定义的自定义控件属性

时间:2011-05-14 21:27:47

标签: wpf vb.net

我在代码隐藏中定义了自定义控件:

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>

我必须编写哪些代码来绑定这些属性?

1 个答案:

答案 0 :(得分:2)

{Binding Path=A, RelativeSource={RelativeSource AncestorType={x:Type MyControl}}}
相关问题