我正在使用 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?
}
}
}
}