如何以编程方式更改wpf窗口中的标题?

tto*_*tom 14 c# wpf

如何以编程方式更改wpf窗口中的标题?

<Window x:Class="Temp.MainWindow"
 ...
 Title="Contacts">
Run Code Online (Sandbox Code Playgroud)

当程序在启动时找到新信息时,将标题从"联系人"更改为"新事物".

Gae*_*aki 30

要更改它,您只需更改代码中的Title属性:

this.Title = "Something new";
Run Code Online (Sandbox Code Playgroud)


Tim*_*ter 15

将它绑定到一个财产

Title="{Binding WindowTitle}"
Run Code Online (Sandbox Code Playgroud)

  • 如果您使用MVVM(或类似)方法,则首选绑定. (4认同)