wpf 的 Window或UserControl绑定自己后台属性

public string Name{get;set;}

 

1.

<Window>
    {Binding Name, RelativeSource={RelativeSource FindAncestor, 
    AncestorType=Window}}
</Window>

 

2.

<Window x:Name="Wd">
<TextBlock Text
="{Binding Name, ElementName=Wd}"/>
</Window>
 

3.

<Window DataContext="{Binding RelativeSource={RelativeSource Self}}">
  <TextBlock Text="{Binding Name}"/>
</Window>

 

posted @ 2020-03-16 17:42  改变你我  阅读(1951)  评论(0编辑  收藏  举报