[英]Setting window title to page title
我目前正在尝试将当前页面标题显示为窗口标题。 我的MainWindow.xaml:
<Window x:Class="Your_choice_1.MainWindow"
namespace:"Your_choice_1"
mc:Ignorable="d"
Title="{Binding Path=Content.Title, ElementName=_mainFrame}"
Height="450" Width="800"
WindowState="Maximized">
<Grid>
<DockPanel>
<Frame x:Name="_mainFrame" Source="Index.xaml" Margin="0,-8,0,8" />
</DockPanel>
</Grid>
</Window>
我知道遗漏了一些内容,因为出于某些原因,编辑器不允许我发布它,但是无论如何重要的是标题绑定。 这是错误的做法吗? 作为标题,我得到项目名称和index.xaml,而不是页面标题本身。
编辑:我想要实现的是,每当新页面显示在框架中时,窗口标题(MainWindow.xaml的标题)就会更新。 窗口标题应与页面标题相同。 在本文中,介绍了我当前使用的解决方案,但是它不能按预期方式工作,而是显示Projectname / URI-to-page,而不是页面标题作为窗口标题。 示例:窗口标题应该是“您的选择-任务”(因为它是页面标题)-实际上,窗口标题是your_choice_1; compontent / Index.xaml
该代码对我来说运行良好:(我看不到您的代码有错误... ???)
您的index.xaml是Page类型还是具有Title属性?
<Window x:Class="WpfApp1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
Title="{Binding Path=Content.Title, ElementName=MainFrame}" Height="450" Width="800">
<Grid>
<Frame x:Name="MainFrame" Source="Index.xaml">
</Frame>
</Grid>
</Window>
Index.xaml
<Page x:Class="WpfApp1.Index"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:WpfApp1"
mc:Ignorable="d"
d:DesignHeight="450" d:DesignWidth="800"
Title="Index Tester">
<Grid>
<TextBlock Text="Hallo"></TextBlock>
</Grid>
</Page>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.