Page 1 of 1

Simple MessageBox C++ class

Posted: 10 Nov 2020, 14:06
by daldegam
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

Re: Simple MessageBox C++ class

Posted: 10 Nov 2020, 17:28
by sfernandez
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.

Re: Simple MessageBox C++ class

Posted: 10 Nov 2020, 17:58
by daldegam
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.

Re: Simple MessageBox C++ class

Posted: 10 Nov 2020, 19:30
by jsantos
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 ...)

Re: Simple MessageBox C++ class

Posted: 10 Nov 2020, 19:37
by sfernandez
Added a new ticket #1833 to our tracker to follow this.

Re: Simple MessageBox C++ class

Posted: 10 Nov 2020, 20:14
by daldegam
Thanks for the replies guys!

Re: Simple MessageBox C++ class

Posted: 08 Dec 2020, 14:45
by jsantos
This was finally added to 3.0.8, thanks for your feedback!