wpf - 将 UWP NavigationView 内容设置为页面显示页面的类型名称
问题描述
我正在使用 XAML IslandsNavigationView
从 .NET Core WPF 应用程序窗口中显示 UWP 控件(我不需要整个导航基础结构——我只需要导航视图控件)。我还有一个从 call 派生的类Page
,Home
我想用它在控件的框架中显示内容。当我将框架的内容设置为Home
类的对象时,我在框架的内容中看到Home
对象的类型名称,就好像ToString()
在对象上被调用而不是渲染其内容。我错过了什么?
using System.Windows;
using MyApp.Wpf.Pages;
using Windows.UI.Xaml.Controls;
namespace MyApp.Wpf
{
public partial class MainWindow : Window
{
private Frame navigationFrame;
public MainWindow()
{
InitializeComponent();
uwpNavigationView.ChildChanged += uwpNavigationView_ChildChanged;
}
private void uwpNavigationView_ChildChanged(object sender, System.EventArgs e)
{
if (uwpNavigationView.Child is NavigationView navigationView)
{
var homeItem = new NavigationViewItem()
{
Content = "Home",
Icon = new FontIcon()
{
Glyph = "\uE80F",
}
};
navigationView.MenuItems.Add(homeItem);
navigationFrame = new Frame();
navigationView.Content = navigationFrame;
navigationView.SelectionChanged += NavigationView_SelectionChanged;
}
}
private void NavigationView_SelectionChanged(NavigationView sender, NavigationViewSelectionChangedEventArgs args)
{
if(args.SelectedItem is NavigationViewItem item)
{
var homePage = new Home();
navigationFrame.Content = homePage; // homepage.ToString() rendered here?
}
}
}
}
解决方案
UWPWindows.UI.Xaml.Controls.Frame
无法呈现 WPFSystem.Windows.Controls.Page
元素。
您应该将该Content
属性设置为 UWPWindows.UI.Xaml.Controls.Page
或使用 WPF System.Windows.Controls.Frame
。
推荐阅读
- python - 使用 openface 和 opensmile 视频提取特征
- javascript - 如何在 Vue 中增加循环
- ios - 在重用之前,UITableViewHeaderFooterView 的 VoiceOver 无法正常工作
- java - 是否可以在 Android Studio 中使用 Firebase 数据库添加子项同时保留旧项?
- time-complexity - 伪代码的时间复杂度
- javascript - 如何防止 setInterval 同时被多次调用?
- bluetooth - 在与 BlueZ 的蓝牙连接期间微调超时?
- r - 如何将逗号分隔的字符串剥离为唯一的子字符串
- python - CodeCoverage 未显示在 Python 项目的 SonarCloud 中
- firebase - Flutter main.dart中的LateInitialization错误