开发者

Bind to custom control properties defined in code behind

I have a custom control defined in code-behind:

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

And here's the Markup:

<ControlTemplate TargetType="{x:Type local:MyControl}">
      <StackPanel>
         <TextBlock Text="{Binding ?????}"/&开发者_如何转开发gt; <!-- A Property -->
         <TextBlock Text="{Binding ?????}"/> <!-- B Property -->
       </StackPanel>
</ControlTemplate>

What code I have to write to bind to those properies?


{Binding Path=A, RelativeSource={RelativeSource AncestorType={x:Type MyControl}}}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜