2010-03-01 28 views
2

在設計時可以通過XAML代碼本身爲WPF窗口賦予標題,並且它在運行時顯示窗口標題。如何爲WPF頁面提供標題

在XAML代碼如下

Window1.Title="FormulaBuilder" 

對於WPF頁面還它在XAML代碼中給出像

Page1.Title="EmployeeMaster" 

但它沒有顯示在運行時

標題

然後我試着通過C#編碼給出標題

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

但它沒有在運行時顯示標題。

回答

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

-1。 OP正在尋找如何根據「Page」的標題設置窗口標題。 – 2010-03-01 06:41:33

+1

這不適用於頁面問題要求頁面(而不是窗口)。 – Paparazzi 2011-10-12 23:50:15

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

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

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

需要注意的是:

的頁面必須是最上位的內容在窗口WINDOWTITLE有一個可以從XAML或代碼做到這一點影響;例如,如果頁面在框架內託管,則設置WindowTitle不會更改主機窗口的標題。

0

對於頁,我們假設用戶的 「標題」 屬性

<Page Title="Page Title Goes here" ... > ...</Page> 
相關問題