<!--MainWindow.xaml-->
<Window x:Class="TestApp.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" />
// MainWindow.xaml.cs
namespace TestApp
{
internal sealed partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
}
}
// App.xaml.cs
namespace TestApp
{
public partial class App : Application
{
public App()
{
InitializeComponent();
}
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
var mainWindow = new MainWindow();
mainWindow.Content = new SubControl();
mainWindow.Activate();
}
}
}
// SubControl.cs
namespace TestApp.Controls
{
internal class SubControl : NavigationView
{
}
}
The above code causes exception when SubControl is loaded.
e.Exception: {"No installed components were detected. (0x800F1000)"}, System.Exception {System.Runtime.InteropServices.COMException}
e.Message: "Cannot apply a Style with TargetType 'Microsoft.UI.Xaml.Controls.NavigationView' to an object of type 'Microsoft.UI.Xaml.Controls.ContentControl'."
If SubControl is created from xaml or inherits Button, TextBox, CheckBox, etc., it will function normally.
What I'm trying to do is create a custom control that inherits NavigationView. In order to implement the part that I want to customize, I think it would be better to do subclassing than applying Behavior.
An exception is thrown when applying breakpoints to "mainWindow.Content = new SubControl();".
If you do not apply breakpoints, there are no exceptions, but the control is not displayed.