[英]Setting UWP NavigationView Content To Page Displays Page's Type Name
I'm using XAML Islands to display a UWP NavigationView
control from within a .NET Core WPF application window (I don't need the whole navigation infrastructure -- I just want the navigation view control).我正在使用 XAML 岛从 .NET Core WPF 应用程序窗口中显示 UWP NavigationView
控件(我不需要整个导航基础结构——我只需要导航视图控件)。 I also have a class derived from Page
called Home
that I want to use to display content in the control's frame.我还有一个从Page
派生的类,称为Home
,我想用它来显示控件框架中的内容。 When I set the frame's content to an object of the Home
class, I see the Home
object's type name in the frame's content, as if ToString()
was being called on the object rather than getting its content rendered.当我将框架的内容设置为Home
类的对象时,我在框架的内容中看到了Home
对象的类型名称,就好像ToString()
是在对象上调用的,而不是渲染其内容。 What am I missing?我错过了什么?
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?
}
}
}
}
A UWP Windows.UI.Xaml.Controls.Frame
cannot render WPF System.Windows.Controls.Page
elements. UWP Windows.UI.Xaml.Controls.Frame
无法呈现 WPF System.Windows.Controls.Page
元素。
You should set the Content
property to a UWP Windows.UI.Xaml.Controls.Page
or use a WPF System.Windows.Controls.Frame
.您应该将Content
属性设置为 UWP Windows.UI.Xaml.Controls.Page
或使用 WPF System.Windows.Controls.Frame
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.