daldegam
Topic Author
Posts: 10
Joined: 17 Jan 2020, 14:54

Simple MessageBox C++ class

10 Nov 2020, 14:06

Good Morning!

I'm starting with NoesisGUI...

I am trying to create a MessageBox in C++.
But I'm not getting ...

I tried to look for an example in the forum and in the examples of the SDK C++ but I also didn't find it.

I'm trying to use the idea of viewtopic.php?f=3&t=862&p=4694#p4692 as a basis

However, I was unable to create the class in c++ that would make the connection between Title / Message / OkText / OkCommand (I don't need the cancel button).

The only way I managed to make this work was to create an x: Name on the elements and set the value like this:
auto* title_component = static_cast<Noesis::TextBlock*>(FindName("Title"));
title_component->SetText("TEXT FROM C++");
Could you please give me an example of what this class would look like in c++?

Thanks.
Leandro Daldegam
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Simple MessageBox C++ class

10 Nov 2020, 17:28

To connect data from C++ to the xaml you can use data binding and expose the data in your user control as dependency properties.
class MessageBox: public UserControl
{
public:
  MessageBox()
  {
    GUI::LoadComponent(this, "UI/Xamls/MessageBox.xaml");
  }

  static const DependencyProperty* TitleProperty;
  
  NS_IMPLEMENT_INLINE_REFLECTION(MessageBox, UserControl, "MyNamespace.MessageBox")
  {
    UIElementData* data = NsMeta<UIElementData>(TypeOf<MessageBox>());
    data->RegisterProperty<String>(TitleProperty, "Title", PropertyMetadata::Create(String("Default Title")));
  }
};
<UserControl x:Class="MyNamespace.MessageBox"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:MyNamespace"
  x:Name="TheMessageBox">
  <Grid Background="#80000000">
    <DockPanel HorizontalAlignment="Center" VerticalAlignment="Center">
      <TextBlock DockPanel.Dock="Top" Text="{Binding Title, ElementName=TheMessageBox}" FontSize="32"/>
    </DockPanel>
  </Grid>
</UserControl>
This was just an example for one of the properties, you can add as many properties as you need to build your message box UI.

You can also add event handlers to react to Button clicks as explained here: https://www.noesisengine.com/docs/Gui.C ... bscription

Anyway, as this is a topic that was asked a few times now, we will add an example to our application framework in a future release so users can use that as reference for their own implementations.
 
daldegam
Topic Author
Posts: 10
Joined: 17 Jan 2020, 14:54

Re: Simple MessageBox C++ class

10 Nov 2020, 17:58

I managed to make it work from your example.

Thanks for the answer.

---

Just one more question, is there any search in the documentation?
I couldn't find where to search for a particular term in it.

Thanks.
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Simple MessageBox C++ class

10 Nov 2020, 19:30

Just one more question, is there any search in the documentation?
Not yet, sorry, but we have plans for that. Right now, the only alternative is using the Class Hierarchy or Google (site:noesisengine.com/docs ...)
 
User avatar
sfernandez
Site Admin
Posts: 2983
Joined: 22 Dec 2011, 19:20

Re: Simple MessageBox C++ class

10 Nov 2020, 19:37

Added a new ticket #1833 to our tracker to follow this.
 
daldegam
Topic Author
Posts: 10
Joined: 17 Jan 2020, 14:54

Re: Simple MessageBox C++ class

10 Nov 2020, 20:14

Thanks for the replies guys!
 
User avatar
jsantos
Site Admin
Posts: 3905
Joined: 20 Jan 2012, 17:18
Contact:

Re: Simple MessageBox C++ class

08 Dec 2020, 14:45

This was finally added to 3.0.8, thanks for your feedback!

Who is online

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