Creating a button dynamically (C++)
Posted: 24 Aug 2014, 04:18
Hi. Sorry if this is a noob question:
I'm trying to create a button dynamically and add it to a loaded XAML via this code:
.h
.cpp
.XAML
(Of course, I just cut an pasted the relevant bits of code above)
Everything about creating the button, adding it to the "SOMEcanvas" sub-canvas and having it display works fine. However, when you mouse over it or click it it does nothing. It acts like a static object rather than a button. Buttons that were created in the XAML work fine.
My assumption is that I'm simply overlooking something? Any help would be appreciated. Thanks...
NOTE 1: The reason for the sub-canvas is that the UI in question will have multiple pages, which is very easy to manage simply by hiding or showing the appropriate sub-canvas, obviously.
NOTE 2: I AM updating the location of this button every few frames using SetRenderTransform() as its location in the display is based off the location of a 3D element in the game world. Not sure if that matters or not, but thought I should mention it regardless.
Finally, as a side question, is there a way to make an image click-able? I mean, I can add an image to a button's content and it works fine. I was just wondering if there was a more efficient means... Thanks again...
I'm trying to create a button dynamically and add it to a loaded XAML via this code:
.h
Code: Select all
void someCLICKevent(Noesis::Core::BaseComponent* obj, const Noesis::Gui::RoutedEventArgs& args);
Noesis::Ptr<Noesis::Gui::Button> someBTN;
Code: Select all
void someCLICKevent(Noesis::Core::BaseComponent* obj, const Noesis::Gui::RoutedEventArgs& args)
{
std::cout << "I've been clicked" << endl;
}
someBTN = *new Noesis::Gui::Button();
someBTN->SetWidth(40);
someBTN->SetHeight(40);
someBTN->SetVisibility(Noesis::Gui::Visibility_Visible);
someBTN->SetClickMode(Noesis::Gui::ClickMode_Press);
SOMEcanvas->GetChildren()->Add(someBTN .GetPtr());
someBTN->Click() += Noesis::Core::MakeDelegate(this, &DISPLAYShmd::someCLICKevent);
Code: Select all
<Canvas xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="1000" Height="800" HorizontalAlignment="Left" Margin="0" VerticalAlignment="Top" Background="#FF000000" TextElement.FontSize="14" TextElement.Foreground="Black">
<Canvas x:Name="SOMEcanvas" Width="1000" Height="800" Canvas.Left="0" Canvas.Top="0">
</Canvas>
</Canvas>
Everything about creating the button, adding it to the "SOMEcanvas" sub-canvas and having it display works fine. However, when you mouse over it or click it it does nothing. It acts like a static object rather than a button. Buttons that were created in the XAML work fine.
My assumption is that I'm simply overlooking something? Any help would be appreciated. Thanks...
NOTE 1: The reason for the sub-canvas is that the UI in question will have multiple pages, which is very easy to manage simply by hiding or showing the appropriate sub-canvas, obviously.
NOTE 2: I AM updating the location of this button every few frames using SetRenderTransform() as its location in the display is based off the location of a 3D element in the game world. Not sure if that matters or not, but thought I should mention it regardless.
Finally, as a side question, is there a way to make an image click-able? I mean, I can add an image to a button's content and it works fine. I was just wondering if there was a more efficient means... Thanks again...