XaeroDegreaz
Topic Author
Posts: 29
Joined: 26 Nov 2013, 04:47

Unity - When inserting a UserControl inside another XAML, Unity can't find the XAML file

12 Mar 2017, 10:13

I have a XAML file that embeds another UserControl. If I load the embedded UserControl's XAML in the NoesisView, it loads properly. When I use the control in another XAML, Unity states that it can't find the XAML file. The strange thing is the thumbnail for the "StartScreen" shows the embedded "OptionScreen" when I go to select it and attach the StartScreen to the NoesisView.

Image
Exception: Xaml not found 'Assets/Ui/OptionScreen.xaml'
NoesisXaml.Load () (at Assets/NoesisGUI/Plugins/NoesisXaml.cs:26)
NoesisView.LoadXaml (Boolean force) (at Assets/NoesisGUI/Plugins/NoesisView.cs:311)
NoesisView.OnEnable () (at Assets/NoesisGUI/Plugins/NoesisView.cs:370)
namespace KazBall.Ui
{
    public partial class OptionScreen : UserControl
    {
        public OptionScreen()
        {
            Initialized += (sender, args) =>
            {
                DataContext = new OptionScreenViewModel();
            };
            InitializeComponent();
        }

        private void InitializeComponent()
        {
            Noesis.GUI.LoadComponent(this, "Assets/Ui/OptionScreen.xaml");
        }
    }
}
<UserControl
    x:Class="KazBall.Ui.OptionScreen"
    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:KazBall.Ui"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="300">
    <TabControl x:Name="tabControl" HorizontalAlignment="Left" Height="100" Margin="89,107,0,0" VerticalAlignment="Top" Width="100">
        <TabItem Header="TabItem">
            <Grid Background="#FFE5E5E5"/>
        </TabItem>
        <TabItem Header="TabItem">
            <Grid Background="#FFE5E5E5" Margin="-47,-67,-18,5"/>
        </TabItem>
    </TabControl>
</UserControl>
<StackPanel
    x:Class="KazBall.Ui.StartScreen"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ui="clr-namespace:KazBall.Ui"
    Orientation="Horizontal"<StackPanel
    x:Class="KazBall.Ui.StartScreen"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:ui="clr-namespace:KazBall.Ui"
    Orientation="Horizontal"
    HorizontalAlignment="Center"
    VerticalAlignment="Bottom"
    Margin="0,0,0,20">
    
    <ui:OptionScreen />

    <Button x:Name="button" Content="Button" Width="75"/>
</StackPanel>
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Unity - When inserting a UserControl inside another XAML, Unity can't find the XAML file

13 Mar 2017, 07:26

Hi!

Yes, this is explained in the Unity Tutorial. You need to add the XAMLs you are not directly referencing in a monobehaviour to the preload list you can find in Noesis Settings.

We want to improve this by properly supporting Unity prefabs. Maybe we are already compatible but we didn't test yet...

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 91 guests