How to make a custom TriggerAction
Posted: 24 Aug 2025, 01:52
Hi there,
I've been trying to get a trigger action working without success.
(Custom Engine in C++, version 3.2.8-indie)
Using the samples as a reference I need to
1. Create a custom class that inherits from `NoesisApp::TriggerActionT<Noesis::DependencyObject>`
2. Implement the reflection in the .h and .cpp using `NS_DECLARE_REFLECTION` and `NS_IMPLEMENT_REFLECTION`
3. In the reflection, set the name and namespace for the action.
4. In the xaml, make an alias for the namespace using `xmlns:l="clr-namespace:..."`
5. Trigger the action using `<Button.Triggers> <EventTrigger ...> <l:Action ...>`
I've been trying to get a trigger action working without success.
(Custom Engine in C++, version 3.2.8-indie)
Using the samples as a reference I need to
1. Create a custom class that inherits from `NoesisApp::TriggerActionT<Noesis::DependencyObject>`
2. Implement the reflection in the .h and .cpp using `NS_DECLARE_REFLECTION` and `NS_IMPLEMENT_REFLECTION`
3. In the reflection, set the name and namespace for the action.
4. In the xaml, make an alias for the namespace using `xmlns:l="clr-namespace:..."`
5. Trigger the action using `<Button.Triggers> <EventTrigger ...> <l:Action ...>`
Code: Select all
// UIAction.h
#pragma once
#include <NsApp/TriggerAction.h>
#include <NsGui/DependencyObject.h>
namespace eng
{
class UIAction final : public NoesisApp::TriggerActionT<Noesis::DependencyObject>
{
protected:
Noesis::Ptr<Noesis::Freezable> CreateInstanceCore() const override;
void Invoke(Noesis::BaseComponent* parameter) override;
private:
NS_DECLARE_REFLECTION(UIAction, NoesisApp::TriggerActionT<Noesis::DependencyObject>)
};
}
Code: Select all
// UIAction.cpp
#include "EnginePCH.h"
#include "Engine/UIAction.h"
#include <NsCore/ReflectionImplement.h>
#include <NsGui/DependencyData.h>
Noesis::Ptr<Noesis::Freezable> eng::UIAction::CreateInstanceCore() const
{
return *new eng::UIAction();
}
void eng::UIAction::Invoke(Noesis::BaseComponent*)
{
Z_LOG(ELog::Debug, "UIAction");
}
NS_IMPLEMENT_REFLECTION(eng::UIAction, "eng.UIAction")
{
}
Code: Select all
// MainWindow.xaml
<Page
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:local="clr-namespace:eng"
Width="400"
Height="200">
<Grid>
<Button Content="Click Me" Width="120" Height="40" HorizontalAlignment="Center" VerticalAlignment="Center">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<local:UIAction/>
</EventTrigger>
</Button.Triggers>
</Button>
</Grid>
</Page>
Code: Select all
[NOESIS/INFO] Noesis Init v3.2.8 (Windows on x86_64 Profile)
[NOESIS/INFO] Inspector listening on port 17629
[NOESIS/INFO] 'Themes/Default.Brushes.xaml' loaded
[NOESIS/INFO] 'Themes/Default.Fonts.xaml' loaded
[NOESIS/INFO] 'Themes/Default.Styles.xaml' loaded
[NOESIS/INFO] 'Themes/Default.xaml' loaded
[NOESIS/ERROR] MainWindow.xaml(10,11): Unknown element type 'local:UIAction' (eng.UIAction)
[NOESIS/INFO] 'MainWindow.xaml' loaded
[NOESIS/INFO] 'pack://application:,,,/Noesis.GUI.Extensions;component/Theme/Fonts/#PT Root UI' loaded
[NOESIS/INFO] 'Themes/Default.Brushes.xaml' loaded
[NOESIS/INFO] 'Themes/Default.Fonts.xaml' loaded
[NOESIS/INFO] 'Themes/Default.Styles.xaml' loaded
[NOESIS/INFO] 'Themes/Default.xaml' loaded
[NOESIS/INFO] 'pack://application:,,,/Noesis.GUI.Extensions;component/Theme/Fonts/#PT Root UI' loaded