Page 1 of 1

Can't render custom UserControl in Unreal engine

Posted: 07 Jan 2024, 02:50
by Michael23
Hi, I'm fairly new to using Noesis so I might be missing something obvious but I've gone over the samples and getting started guides and haven't been able to find what I'm doing wrong.

If I create a simple user control:
using System.Windows.Controls;

namespace Ghana_Blend
{
    public partial class SimpleUserControl : UserControl
    {
        public SimpleUserControl()
        {
            InitializeComponent();
        }
    }
}
<UserControl x:Class="Ghana_Blend.SimpleUserControl"
             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:Ghana_Blend"
             mc:Ignorable="d">
    <Grid>
        <Rectangle Width="100" Height="100" Fill="#FFBD2FB1"></Rectangle>
    </Grid>
</UserControl>
I am able to render it in Unreal engine directly by adding it to viewport in my blueprint like so:
Image

However, if I try to nest in inside of another Xaml file:
<Page x:Class="Ghana_Blend.GameOverlay"
      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:Ghana_Blend" d:DataContext="{d:DesignInstance Type=local:GameOverlayViewModel}"
      mc:Ignorable="d"
      Title="GameOverlay">
      <Grid>
      	      <TextBlock Text="Test" Foreground="White"/>
              <local:SimpleUserControl></local:SimpleUserControl>
    </Grid>
</Page>
Then "Test" will render but not the SimpleUserControl. I also receive a warning in Unreal engine:
LogNoesis: Warning: /Game;component/Ghana_Blend/GameOverlay.xaml(215,9): Unknown element type 'local:SimpleUserControl' (Ghana_Blend.SimpleUserControl)
Are there other steps to get a custom user control to render in Unreal engine? For reference, I'm using UE 5.1 and Noesis 3.2.1.

Thanks in advance.

Re: Can't render custom UserControl in Unreal engine

Posted: 09 Jan 2024, 12:22
by sfernandez
Hello,

As explained in Unreal's tutorial, classes that appear in the XAML have to be registered so they can be created using the component factory.

Also remember as indicated in the tutorial to call Noesis::GUI::LoadComponent() in order to load the XAML associated to your UserControl.

Let us know if you find any trouble with that.