jatingargrx
Topic Author
Posts: 2
Joined: 21 Apr 2022, 12:33

Setting DataContext using Unreal C++ class

01 May 2022, 16:10

Hi,
I am working on Unreal Engine and was trying to set a custom object class as data context, but can't construct the class in 'View' (Screenshot attached)
https://drive.google.com/file/d/1Rur29k ... sp=sharing

My C++ code
DataContext class name - BindingTest
#include "CoreMinimal.h"
#include "UObject/NoExportTypes.h"
#include "NoesisRuntime.h"
#include "BindingTest.generated.h"

/**
 * 
 */
UCLASS()
class NOESISGUISAMPLE_API UBindingTest : public UObject
{
	GENERATED_BODY()

public:
	UPROPERTY(BlueprintReadWrite)
	int32 Value = 0;

	UFUNCTION(BlueprintCallable)
	void SetValue(int32 value1);

	UFUNCTION(BlueprintCallable)
	int32 GetValue() const;

	UFUNCTION(BlueprintCallable)
	void UpButton_Click();

	UFUNCTION(BlueprintCallable)
	void DownButton_Click();
};
cpp file
#include "BindingTest.h"

void UBindingTest::SetValue(int32 value1)
{
	Value = value1;
}

int32 UBindingTest::GetValue() const
{
	return Value;
}

void UBindingTest::UpButton_Click(){
	Value++;
	UE_LOG(LogTemp,Warning, TEXT("Up button clicked"));
}

void UBindingTest::DownButton_Click()
{
	Value--;
	UE_LOG(LogTemp, Warning, TEXT("Down button clicked"));
}
My Xaml file is (ButtonTest.xaml)
<UserControl x:Class="Demo.GUI.ButtonTest"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             x:Name="NumericUpDownControl">
 
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition/>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
            <ColumnDefinition Width="Auto"/>
        </Grid.ColumnDefinitions>

        <Border Grid.RowSpan="2" Grid.ColumnSpan="2" BorderThickness="1"
            BorderBrush="#40484F" Background="#20282F"/>

        <TextBlock Grid.RowSpan="2" VerticalAlignment="Center" Margin="5,3,4,3" Width="50" Text="{Binding Value}"/>

        <RepeatButton Name="UpButton" Grid.Column="1" Grid.Row="0" Padding="4,1" Margin="0,2,2,0" Command="{Binding UpButton_Click}">
            <Path Data="M1,1L4,4 7,1" Stroke="Black" StrokeThickness="2"
            StrokeStartLineCap="Round" StrokeEndLineCap="Round" RenderTransformOrigin="0.5,0.5">
                <Path.RenderTransform>
                    <ScaleTransform ScaleY="-1"/>
                </Path.RenderTransform>
            </Path>
        </RepeatButton>

        <RepeatButton Name="DownButton" Grid.Column="1" Grid.Row="1" Padding="4,1" Margin="0,0,2,2" Command="{Binding DownButton_Click}">
            <Path Data="M1,1L4,4 7,1" Stroke="Black" StrokeThickness="2"
            StrokeStartLineCap="Round" StrokeEndLineCap="Round"/>
        </RepeatButton>

    </Grid>
</UserControl>
The same thing is working if I make the Data Context class as a blueprint class. But want to use c++
I am new to Noesis. Please let me know if I am missing anything.
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Setting DataContext using Unreal C++ class

02 May 2022, 12:36

The class must be marked as BlueprintType, since you want to use the result in blueprint:
https://docs.unrealengine.com/4.27/en-U ... pecifiers/
 
jatingargrx
Topic Author
Posts: 2
Joined: 21 Apr 2022, 12:33

Re: Setting DataContext using Unreal C++ class

04 May 2022, 20:06

The class must be marked as BlueprintType, since you want to use the result in blueprint:
https://docs.unrealengine.com/4.27/en-U ... pecifiers/
Thank you soo much. I totally missed it.
UCLASS(Blueprintable) 

Who is online

Users browsing this forum: No registered users and 94 guests