How to give title to WPF pages

后端 未结 3 1075
没有蜡笔的小新
没有蜡笔的小新 2021-01-14 09:44

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.

the code in the XAML is like

相关标签:
3条回答
  • 2021-01-14 10:29

    For pages we suppose to user "Title" property

    <Page  Title="Page Title Goes here" ... >   ...</Page>
    
    0 讨论(0)
  • 2021-01-14 10:34

    From the documentation (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.
    

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

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

    or

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

    Note that:

    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.

    0 讨论(0)
  • 2021-01-14 10:46

    Try out this one

    <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>
    
    0 讨论(0)
提交回复
热议问题