如何为WPF页面赋予标题

Luk*_*man 2 c# wpf xaml

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

XAML中的代码就像

Window1.Title="FormulaBuilder"
Run Code Online (Sandbox Code Playgroud)

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

Page1.Title="EmployeeMaster"
Run Code Online (Sandbox Code Playgroud)

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

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

Page1 obj=new Page1();
obj.Title="EmployeeMaster";
Run Code Online (Sandbox Code Playgroud)

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

Ben*_*gan 7

从文档(Page.Title):

Title属性的值不会显示在Page上,也不会显示在托管页面的窗口的标题栏中. 而是设置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.
Run Code Online (Sandbox Code Playgroud)

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

<Page WindowTitle="Page Title" ... >
   ...
</Page>
Run Code Online (Sandbox Code Playgroud)

要么

Page myPage = new Page();
myPage.WindowTitle = "Page Title";
Run Code Online (Sandbox Code Playgroud)

注意:

Page必须是WindowTitle窗口中最重要的内容才能生效; 例如,如果页面位于框架内,则设置WindowTitle不会更改主机窗口的标题.


zap*_*ing 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>
Run Code Online (Sandbox Code Playgroud)

  • -1。OP正在寻找如何根据“Page”标题设置窗口标题。 (2认同)