Triggering event from xaml -> c++?
Posted: 29 May 2023, 23:27
I feel like this is a simple thing but I can't seem to get these events to fire.
I've got a collection of RealmUI_Tell that are bound as the ItemsSource of the tab control. The content bindings work (Sender, StaffTitle, and Text)
But I'm trying to get an event to fire when the Close button is clicked, but can't seem to get this event to fire. I tried using the NsEvent macro to associate OnCloseClicked with the evt_close RoutedEventHandler, and then I register a lambda with evt_close when I create the RealmUI_Tell, however this event doesn't get fired, and there is no error or otherwise any output from Noesis when registering this stuff or clicking the button - so I'm not sure where the problem is in hooking this up properly.
Some advice would be greatly appreciated!
I've got a collection of RealmUI_Tell that are bound as the ItemsSource of the tab control. The content bindings work (Sender, StaffTitle, and Text)
But I'm trying to get an event to fire when the Close button is clicked, but can't seem to get this event to fire. I tried using the NsEvent macro to associate OnCloseClicked with the evt_close RoutedEventHandler, and then I register a lambda with evt_close when I create the RealmUI_Tell, however this event doesn't get fired, and there is no error or otherwise any output from Noesis when registering this stuff or clicking the button - so I'm not sure where the problem is in hooking this up properly.
Some advice would be greatly appreciated!
Code: Select all
struct RealmUI_Tell : Noesis::BaseComponent
{
Noesis::String sender;
Noesis::String staff_title;
Noesis::Ptr<Noesis::TextBlock> text = Noesis::MakePtr<Noesis::TextBlock>();
Noesis::RoutedEventHandler evt_close;
const Noesis::String& GetSender() const
{
return sender;
}
const Noesis::String& GetStaffTitle() const
{
return staff_title;
}
Noesis::TextBlock* GetText() const
{
return text;
}
NS_IMPLEMENT_INLINE_REFLECTION(RealmUI_Tell, Noesis::BaseComponent)
{
NsProp("Sender", &RealmUI_Tell::GetSender);
NsProp("StaffTitle", &RealmUI_Tell::GetStaffTitle);
NsProp("Text", &RealmUI_Tell::GetText);
NsEvent("OnCloseClick", &RealmUI_Tell::evt_close);
}
};
Code: Select all
<TabControl TabStripPlacement="Left" x:Name="TellsTabs">
<TabControl.ItemTemplate>
<DataTemplate>
<Label Content="{Binding Sender}" />
</DataTemplate>
</TabControl.ItemTemplate>
<TabControl.ContentTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25pt" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid Grid.Row="0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<Label Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Center" Content="{Binding StaffTitle}" />
<StackPanel Grid.Column="1" HorizontalAlignment="Right" Orientation="Horizontal">
<Button Click="{Binding OnCloseClick}">Close</Button>
<Button>Ignore</Button>
<Button>Report</Button>
</StackPanel>
</Grid>
<ContentControl Grid.Row="1" Content="{Binding Text}" />
</Grid>
</DataTemplate>
</TabControl.ContentTemplate>
</TabControl>