如何为WPF页面赋予标题 [英] How to give title to WPF pages

查看:66
本文介绍了如何为WPF页面赋予标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以在设计时通过XAML代码本身为WPF窗口提供标题,并在运行时将其显示给窗口.

It is possible to give the title to WPF window through XAML code itself at design time and it is showing the title to window at runtime.

XAML中的代码就像

the code in the XAML is like

Window1.Title="FormulaBuilder"

对于WPF页面,它也在XAML代码中给出,例如

For the WPF pages also it is given in the XAML code like

Page1.Title="EmployeeMaster"

但是它没有在运行时显示标题

But it is not showing the title at Runtime

然后我尝试通过C#编码给标题

Then I tried to give the title through C# coding

Page1 obj=new Page1();
obj.Title="EmployeeMaster";

但是它没有在运行时显示标题.

But it is not showing the title at runtime.

推荐答案

摘自文档(

标题"属性的值为没有按页面显示,也没有从标题栏显示托管页面的窗口.而是将 WindowTitle 设置为更改主机窗口的标题.

The value of the Title property is not displayed by Page, nor is it displayed from the title bar of the window that is hosting a Page. Instead, you set WindowTitle to change the title of a host window.

标题也可用于生成导航历史的名称一段导航的条目内容.以下数据用于自动构造一个导航历史记录条目名称,在优先顺序:

Title can also be used to generate the name of the navigation history entry for a piece of navigated content. The following pieces of data are used to automatically construct a navigation history entry name, in order of precedence:

* 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.

因此,看来您应该尝试使用

So, it seems you should try using Page.WindowTitle. You can do this from xaml or code:

<Page WindowTitle="Page Title" ... >
   ...
</Page>

Page myPage = new Page();
myPage.WindowTitle = "Page Title";

请注意:

页面必须是窗口中最顶层的内容,WindowTitle才能生效;例如,如果页面托管在框架中,则设置WindowTitle不会更改宿主窗口的标题.

The Page must be the topmost piece of content in a window for WindowTitle to have an effect; if a Page is hosted within a Frame, for example, setting WindowTitle does not change the title of the host window.

这篇关于如何为WPF页面赋予标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆