View Issue Details

IDProjectCategoryView StatusLast Update
0001771NoesisGUIUnity3Dpublic2020-08-10 17:36
Reporterreal_mikhailAssigned Tosfernandez 
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionno change required 
Product Version3.0.2 
Target Version3.0.5Fixed in Version3.0.5 
Summary0001771: Noesis doesn't allow to use "custom UserControl" in xaml
DescriptionCurrently for each UI's code behind I have following code:
```
#if UNITY_5_3_OR_NEWER
#define NOESIS
using Noesis;
#else
using System.Windows.Controls;
#endif

    public partial class Testing : UserControl
    {
        public Testing()
        {
            InitializeComponent();
        }

#if NOESIS
        private void InitializeComponent()
        {
            Noesis.GUI.LoadComponent(this, "Assets/Root/UI/Testing.xaml");
        }
#endif
    }
```

I wanted to avoid that, and for that I've created my custom UserControl class:
```
#if UNITY_5_3_OR_NEWER
#define NOESIS
#endif

namespace Alchemy.UI.Misc
{
    public class UserControl :
#if NOESIS
        Noesis.UserControl
#else
        System.Windows.Controls.UserControl
#endif
    {
#if NOESIS
        protected void InitializeComponent()
        {
            var filepath = $"Assets/Root/UI/{GetType().Name}.xaml";
            Noesis.GUI.LoadComponent(this, filepath);
        }
#endif
    }
}
```

And this way I don't have to use #if directives in my UIs. Xaml in that case looks following:
```
<misc:UserControl x:Class="Alchemy.UI.Testing"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:local="clr-namespace:Alchemy.UI"
             xmlns:misc="clr-namespace:Alchemy.UI.Misc"
             mc:Ignorable="d"
             d:DesignHeight="1080"
             d:DesignWidth="1920"
             d:DataContext="{d:DesignInstance {x:Type local:TestingViewModel}}">
    <Grid>
    </Grid>
</misc:UserControl>
```

And that works perfectly in WPF (in blend solution). But in Unity (in Noesis) I'm getting following error:
```
[noesis] Assets/Root/UI/Testing.xaml(1): Unknown type 'Alchemy.UI.Misc.UserControl'.
UnityEngine.Debug:LogError(Object)
NoesisUnity:UnityLog(Int32, String) (at Assets/NoesisGUI/Plugins/NoesisUnity.cs:141)
Noesis.GUI:Noesis_LoadXaml(String)
Noesis.GUI:LoadXaml(String) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:244)
NoesisXaml:Load() (at Assets/NoesisGUI/Plugins/NoesisXaml.cs:30)
NoesisPostprocessor:ImportXaml(String, Boolean, Boolean, Boolean&) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:372)
NoesisPostprocessor:ImportXaml(String, Boolean, Boolean) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:299)
NoesisPostprocessor:ImportAssets(String[], Boolean, UpdateProgress) (at Assets/NoesisGUI/Plugins/Editor/NoesisPostprocessor.cs:78)
```
Tagsxaml
PlatformAny

Activities

sfernandez

sfernandez

2020-08-10 12:02

manager  

CustomRoot.unitypackage (4,360 bytes)
sfernandez

sfernandez

2020-08-10 12:02

manager   ~0006557

Hello, I might be missing something because in the attached test I made it is working as expected (using NoesisGUI 3.0.4).
Do you have anything different in your project?
real_mikhail

real_mikhail

2020-08-10 17:13

reporter   ~0006564

Hm... I cannot reproduce it anymore. Might be my bad - there was a compilation error in another script (ambiguous reference to UserControl) and because of that Noesis failed to process/import xaml with this custom UserControl. As soon as I fixed this C# error -- importing was successful. Sorry for troubles.
sfernandez

sfernandez

2020-08-10 17:36

manager   ~0006565

That makes sense, if assembly was not compiled the parser wouldn't be able to find your custom type and failed.
Closing this.

Issue History

Date Modified Username Field Change
2020-08-04 18:52 real_mikhail New Issue
2020-08-04 18:52 real_mikhail Tag Attached: xaml
2020-08-04 18:54 real_mikhail Description Updated View Revisions
2020-08-05 11:11 jsantos Assigned To => sfernandez
2020-08-05 11:11 jsantos Status new => assigned
2020-08-05 11:11 jsantos Target Version => 3.0.5
2020-08-10 12:02 sfernandez File Added: CustomRoot.unitypackage
2020-08-10 12:02 sfernandez Note Added: 0006557
2020-08-10 12:02 sfernandez Status assigned => feedback
2020-08-10 17:13 real_mikhail Note Added: 0006564
2020-08-10 17:13 real_mikhail Status feedback => assigned
2020-08-10 17:36 sfernandez Note Added: 0006565
2020-08-10 17:36 sfernandez Status assigned => resolved
2020-08-10 17:36 sfernandez Resolution open => no change required
2020-08-10 17:36 sfernandez Fixed in Version => 3.0.5