gpt4 book ai didi

c# - 如何为 WPF 页面赋予标题

转载 作者:行者123 更新时间:2023-11-30 20:12:43 32 4
gpt4 key购买 nike

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

XAML 中的代码是这样的

Window1.Title="FormulaBuilder"

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

Page1.Title="EmployeeMaster"

但它在运行时不显示标题

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

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

但它在运行时不显示标题。

最佳答案

来自文档(Page.Title):

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.

所以,看来你应该尝试使用 Page.WindowTitle 。您可以从 xaml 或代码执行此操作:

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

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

注意:

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.

关于c# - 如何为 WPF 页面赋予标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2354200/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com