Page 1 of 1

LoadXaml throws a warning "does not inherit from x: Class"

Posted: 04 Oct 2020, 09:57
by Logrus
I have a class hierarchy:
class WindowEx : public NoesisApp::Window
{
...
};

class DesignerMainWindow : public WindowEx
{
...
};
Designer XAML
<Window
    x:Class="DesignerMainWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006">
    <Grid/>
</Window>

This is how the Designer class is instantiated correctly
			
auto symbol = Symbol("DesignerMainWindow");
			
if (Factory::IsComponentRegistered(symbol)) {
	if (auto component = DynamicPtrCast<WindowEx>(Factory::CreateComponent(symbol))) {
		component->SetIsActive(true);
		component->Show();
		return;
	}
}
And this is how it issues a warning,
"Component type 'WindowEx' does not inherit from x:Class type 'DesignerMainWindow'.."
auto root = Noesis::GUI::LoadXaml("Designer/DesignerMainWindow.xaml");
if (auto wnd = DynamicPtrCast<WindowEx>(root)) {
}
The window is created, but the style specified in WindowEx is not inherited

Re: LoadXaml throws a warning "does not inherit from x: Class"

Posted: 07 Oct 2020, 10:49
by sfernandez
Is it possible that you are defining a xaml for WindowEx and you are calling LoadComponent for WindowEx constructor too?
You can't do that, only the instantiated class can have an associated xaml.

But you can define a ControlTemplate for WindowEx and then use it in your DesignerMainWindow by setting its Template property (explicitly or using a style).

Re: LoadXaml throws a warning "does not inherit from x: Class"

Posted: 07 Oct 2020, 13:25
by Logrus
Yes, in the WindowEx constructor, I called LoadComponent.

Thanks

Re: LoadXaml throws a warning "does not inherit from x: Class"

Posted: 13 Oct 2020, 16:36
by sfernandez
Were you able to make it work using the ControlTemplate as I suggested?
Can we mark this as solved?

Re: LoadXaml throws a warning "does not inherit from x: Class"

Posted: 15 Oct 2020, 18:36
by Logrus
Yes, it works with ControlTemplate.
Thanks

Re: LoadXaml throws a warning "does not inherit from x: Class"

Posted: 15 Oct 2020, 18:41
by sfernandez
Great, thanks for the update.