WPF将TextBlock绑定到Window的标题

tca*_*les 4 vb.net wpf binding textblock title

我的主窗口上有一个TextBlock.我想将它的文本绑定到窗口的标题上..例如:myWindow.Title.

这一直困扰着我,我已经用Google搜索过去了,任何帮助都表示赞赏.

谢谢.

Mat*_*ton 12

最简单的方法是绑定回父窗口:

<TextBlock Text="{Binding Title,RelativeSource={RelativeSource FindAncestor,AncestorType=Window}}"  />
Run Code Online (Sandbox Code Playgroud)