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). I also have a class derived from Page
called Home
that I want to use to display content in the control's frame. 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. 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.
You should set the Content
property to a UWP Windows.UI.Xaml.Controls.Page
or use a WPF System.Windows.Controls.Frame
.