可以在设计时通过XAML代码本身为WPF窗口提供标题,并在运行时显示窗口的标题。
XAML中的代码就像
Window1.Title="FormulaBuilder"
对于WPF页面,它也在XAML代码中给出,如
Page1.Title="EmployeeMaster"
但它没有在运行时显示标题
然后我尝试通过C#编码提供标题
Page1 obj=new Page1();
obj.Title="EmployeeMaster";
但它没有在运行时显示标题。
答案 0 :(得分:7)
从文档(Page.Title):
Title属性的值是 不是由页面显示,也不是 从标题栏显示 托管页面的窗口。 而是将 WindowTitle 设置为 更改主机窗口的标题。
标题也可用于生成 导航历史记录的名称 导航一段导航 内容。以下数据 用于自动构建一个 导航历史记录条目名称 优先顺序:
* The attached Name attribute. * The Title property. * The WindowTitle property and the uniform resource identifier (URI) for the current page * The uniform resource identifier (URI) for the current page.
因此,您似乎应该尝试使用 Page.WindowTitle 。您可以从xaml或代码执行此操作:
<Page WindowTitle="Page Title" ... >
...
</Page>
或
Page myPage = new Page();
myPage.WindowTitle = "Page Title";
请注意:
Page必须是WindowTitle窗口中最重要的内容才能生效;例如,如果页面在框架中托管,则设置WindowTitle不会更改主机窗口的标题。
答案 1 :(得分:0)
试试这个
<Window
x:Class="MyWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="The Title"
Height="300"
Width="300">
</window>
答案 2 :(得分:0)
对于页面,我们假设用户使用“标题”属性
<Page Title="Page Title Goes here" ... > ...</Page>