我当前正在尝试将当前页面标题显示为窗口标题。我的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的标题)就会更新。窗口标题应与页面标题相同。 In this article 提出了我当前使用的解决方案,但未按预期工作,显示Projectname / URI-to-page,而不是页面标题作为窗口标题。 例: 窗口标题应该是“您的选择-任务”(因为它是页面标题)-实际上,窗口标题是your_choice_1; compontent / Index.xaml
答案 0 :(得分:0)
此代码对我来说运行良好:(我看不到您的代码有错误... ???)
您的index.xaml是Page类型还是具有Title属性?
> Connecting database...
Exception in thread "main" java.lang.IllegalStateException: Cannot connect the database!
at election.ElectionApp.main(ElectionApp.java:251)
Caused by: java.sql.SQLException: null, message from server: "Host 'MyComputer.local' is not allowed to connect to this MySQL server"
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1040)
at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2191)
at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly (ConnectionImpl.java:2222)
at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2017)
at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
at java.lang.reflect.Constructor.newInstance(Unknown Source)
at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
at java.sql.DriverManager.getConnection(Unknown Source)
at java.sql.DriverManager.getConnection(Unknown Source)
at Election.ElectionApp.main(ElectionApp.java:248)
Index.xaml
<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>