Arca INC
Topic Author
Posts: 4
Joined: 01 May 2024, 18:49

Get content from TextBox and Button click events

20 May 2024, 17:38

Hi,

I would like to know how can I get data from my Gui. I tried serveral things but no one works.
I have added a "x:Name" on my element but how to get it in C++ ?

Second thing, how can I get the event of "User Click" on a element and call a C++ function ?

Here is my code

.h
 #pragma once

#include "NoesisInstance.h"
#include "ConnectingGUI.generated.h"

UCLASS()
class UConnectingGUI : public UNoesisInstance
{
	GENERATED_BODY()
	
public:
	UConnectingGUI();
	UPROPERTY()
	FString NotificationMessage = "";

	void XamlLoaded();

}; 
.cpp
#include "ConnectingGUI.h"

#include "NoesisTypeClass.h"
#include "NoesisXaml.h"

UConnectingGUI::UConnectingGUI()
{
	UNoesisXaml* MyXaml = LoadObject<UNoesisXaml>(nullptr, TEXT("/Game/ConnectingGUI/MainWindow"));
	BaseXaml = MyXaml;

	NoesisNotifyPropertyChanged(MyXaml, "NotificationMessage");
}

void UConnectingGUI::XamlLoaded()
{
	Super::XamlLoaded();
	
	UE_LOG(LogTemp, Display, TEXT("XamlLoaded"));
}
And my xaml
<UserControl x:Class="ConnectingGUI.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:ConnectingGUI"
             mc:Ignorable="d"
        FontFamily="Font/#Aero Matics"
        FontSize="24"
        Background="Transparent"
        d:DesignHeight="1080" d:DesignWidth="1920">

    <UserControl.Resources>

    </UserControl.Resources>

    <Grid>

        <Label FontSize="24" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,513,0,0" Background="White">
            Menu de Test
        </Label>

        <TextBox HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,559,0,0" TextChanged="TextBox_TextChanged" Width="129">
            <TextBox.Text>Une IP</TextBox.Text>
        </TextBox>

        <TextBox HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,594,0,0" TextChanged="TextBox_TextChanged" Width="128">
            <TextBox.Text>Un Port</TextBox.Text>
        </TextBox>

        <Button x:Name="Connecting" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,629,0,0" Content="Se connecter">
        </Button>

        <Grid HorizontalAlignment="Right" VerticalAlignment="Bottom" Margin="20">
            <Label Name="notificationLabel" FontSize="16" Foreground="Red" Content="{Binding NotificationMessage}" />
        </Grid>

    </Grid>
</UserControl>
Thanks in advance.
 
User avatar
hcpizzi
Site Admin
Posts: 331
Joined: 09 Feb 2012, 12:40

Re: Get content from TextBox and Button click events

22 May 2024, 02:16

Hi,

The easiest way to do it is to set a DataContext on your NoesisInstance, and then use a Binding on the Command property of your Button.

You can see an example in our Buttons Sample (the three buttons are at the bottom of the XAML). In that sample the DataContext is a Blueprint, but you can use a native UObject derived class with a native UFUNCTION too.

You can find more information related to Bindings in Unreal here: https://www.noesisengine.com/docs/Gui.C ... ty-binding

Hope this helps.

Who is online

Users browsing this forum: Baidu [Spider], Bing [Bot] and 21 guests