markj
Topic Author
Posts: 4
Joined: 11 Jun 2014, 01:08

Error thrown when building XAML derived from non-XAML base

11 Jun 2014, 01:33

I have a derived class set up like so:

WindowBase.cs
    [Noesis.Extended]
    public class WindowBase : ContentControl
GenericWindow.cs
    [Noesis.Extended]
    [Noesis.UserControlSource("Assets/UI/GenericWindow.xaml")]
    public class GenericWindow : WindowBase
The GenericWindow XAML file:
<local:WindowBase
	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"
	xmlns:local="clr-namespace:GameUI"
	mc:Ignorable="d"
	x:Class="GameUI.GenericWindow"
	x:Name="WindowBase"
	d:DesignWidth="350" d:DesignHeight="296" FontFamily="/GameUI;component/Fonts/#Arial" Content="WindowBase">
	<local:WindowBase.Resources>
		<ResourceDictionary>
			<ResourceDictionary.MergedDictionaries>
				<ResourceDictionary Source="GameControls.xaml"/>
			</ResourceDictionary.MergedDictionaries>
		</ResourceDictionary>
	</local:WindowBase.Resources>
</local:WindowBase>
Note that WindowBase has no XAML associated with it. It is pure C#, as required by WPF. When I build my Noesis assets, I get the following error:

[error] [DX9] Assets/UI/GenericWindow.xaml
Parsing GameUI.WindowBase (@1,1).
'GameUI.GenericWindow' doesn't inherit from 'GameUI.WindowBase'
-Void OnLog(Int32, System.String) (NoesisBuildToolKernel.cs:194)
-Void Build() (NoesisBuildToolKernel.cs:140)
-Void Build(System.String) (NoesisSettings.cs:276)

Any suggestions for why I am getting this error?

Thanks,
Mark
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Error thrown when building XAML derived from non-XAML ba

12 Jun 2014, 21:38

I tried your sample and after scripts are compiled by Unity, the xaml is built without problems.

Just for your information, you don't have to specify the [Noesis.UserControlSource] attribute if you are not deriving from UserControl. This attribute is necessary to automatically load the specified xaml file when creating your UserControl. For example:
[Noesis.Extended]
[Noesis.UserControlSource("Assets/UI/MyUserControl.xaml")
public class MyUserControl : UserControl
{
}

void SomeFunction(Noesis.ContentControl container)
{
    container.SetContent(new MyUserControl());
}
In this code, when new MyUserControl() is called, the associated MyUserControl.xaml gets automatically loaded, and then it is set as the content of the supplied container.

If you are inheriting from ContentControl, no xaml is associated with the user class. You have to manually load the xaml, that will create your user class (the one specified in x:Class) when xaml gets loaded.
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Error thrown when building XAML derived from non-XAML ba

13 Jun 2014, 19:26

Hi Mark,

I found a situation where the error you commented can be reproduced.

If you have a class like this:
public class GenericWindow : Noesis.ContentControl { }
And a xaml like this:
<ContentControl x:Class="GenericWindow" ... />
Already builded and playable in Unity. And then you modify it at once to this:
public class WindowBase : Noesis.ContentControl { }
public class GenericWindow : WindowBase { }
<local:WindowBase x:Class="GenericWindow" ... />
When you come back to Unity, Unity triggers our AssetPostProcessor first and then compiles the script. Because of this order, we are building the xaml against the old compiled script, where GenericWindow derives from ContentControl, and that's why you get the 'GameUI.GenericWindow' doesn't inherit from 'GameUI.WindowBase' error message.

We are working on a solution to avoid this undesired behavior. It will be fixed for the next release.

Thanks for reporting.
 
markj
Topic Author
Posts: 4
Joined: 11 Jun 2014, 01:08

Re: Error thrown when building XAML derived from non-XAML ba

16 Jun 2014, 21:23

Thanks for the replies. I was able to fix the error by moving the derived file GenericWindow.xaml.cs to a folder that would be built after the folder that contained WindowBase.xaml.cs. So it appears the build order of scripts matters.
 
User avatar
sfernandez
Site Admin
Posts: 1918
Joined: 22 Dec 2011, 19:20

Re: Error thrown when building XAML derived from non-XAML ba

01 Jul 2014, 14:45

In 1.1.9 we improved the post-process mechanism. Now xaml resources are built after Unity ends to compile, if there was any modified, the scripts. This way, xaml resource will be built against the last version of your custom classes.

Who is online

Users browsing this forum: No registered users and 1 guest