stonstad
Topic Author
Posts: 84
Joined: 06 Jun 2016, 18:14

Adding XAML Dependencies

07 Mar 2019, 01:09

I'm not sure if this is a bug. I have a top-level screen (RootContainer.xaml/.cs) that contains multiple user controls. i.e. Control1, Control2, Control3. Initially, I had all three controls present and based on user interaction, I show one of the three controls by changing visibility. These controls are essentially screens.

Since these screens have deep nested hierarchies of content and user controls, I decided to instantiate them as needed and remove them from the visual tree after they are finished. There were no problems.

However, after restarting Unity I am finding that I frequently -- but not always -- get the same error from Noesis.GUI.LoadComponent(...)
[noesis] Xaml not found 'Assets/User Interface/Screens/Character Selection/CharacterSelectionScreen.xaml'
UnityEngine.Debug:LogError(Object)
NoesisUnity:UnityLog(Int32, String) (at Assets/NoesisGUI/Plugins/NoesisUnity.cs:116)
Noesis.GUI:Noesis_LoadComponent()
Noesis.GUI:LoadComponent(Object, String) (at Assets/NoesisGUI/Plugins/API/Core/NoesisGUI.cs:231)
CharacterSelectionScreen:InitializeComponent() (at Assets/User Interface/Screens/Character Selection/CharacterSelectionScreen.cs:34)
CharacterSelectionScreen:.ctor() (at Assets/User Interface/Screens/Character Selection/CharacterSelectionScreen.cs:29)
RootContainer:ShowCharacterSelectionScreen(List`1) (at Assets/User Interface/RootContainer.cs:52)
So I removed RootContainer from my Noesis view and set CharacterSelectionScreen directly -- and tada, it works! I then switched back to my RootContainer control and everything works. But now the other controls cannot be found.

This feels like a bug -- but I wanted to throw this out there for your consideration just in case it is user error. The version of Noesis I am using is 2.2.0b6.
Last edited by stonstad on 07 Mar 2019, 15:50, edited 3 times in total.
 
User avatar
jsantos
Site Admin
Posts: 2417
Joined: 20 Jan 2012, 17:18
Contact:

Re: Possible Bug?

07 Mar 2019, 01:37

I'm not sure if this is a bug. I have a top-level screen (RootContainer.xaml/.cs) that contains multiple user controls. i.e. Control1, Control2, Control3. Initially, I had all three controls present and based on user interaction, I show one of the three controls by changing visibility. These controls are essentially screens.

Since these screens have deep nested hierarchies of content and user controls, I decided to instantiate them as needed and remove them from the visual tree after they are finished. There were no problems.
This is almost for sure a dependency issue. All XAMLs loaded at runtime must be referenced someway to make sure Unity loads them and package them. We automatically detect the usage of usercontrols in a XAML (this can be verified in the XAML inspector, all dependencies are shown there) and inject the dependencies. But, if those XAMLs are loaded by code then you need to inject a manual dependency. We offer the follow extensions in the XAML to express dependencies:
<UserControl
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:noesis="clr-namespace:NoesisGUIExtensions"
  x:Class="Localization.MainWindow"
  FontFamily="./#Oxygen, ./#FontopoNIHONGO"
  Foreground="#FF488EB5">

  <noesis:Xaml.Dependencies>
    <noesis:Dependency Source="Language-en.xaml"/>
    <noesis:Dependency Source="Language-fr.xaml"/>
    <noesis:Dependency Source="Language-jp.xaml"/>
  </noesis:Xaml.Dependencies>

</UserControl>
This is explained in the Unity guide and we also provide a few examples using that mechanism (the localization one for example).
 
stonstad
Topic Author
Posts: 84
Joined: 06 Jun 2016, 18:14

Re: Possible Bug?

07 Mar 2019, 03:21

Thank you! Noesis is so much like WPF that I forget there are subtle differences. Thank you for the explanation.
 
User avatar
sfernandez
Site Admin
Posts: 1503
Joined: 22 Dec 2011, 19:20

Re: Adding XAML Dependencies

08 Mar 2019, 10:18

I think we can mark this as solved.

Who is online

Users browsing this forum: Baidu [Spider], chengran and 4 guests