-
- realm_mike
- Posts: 5
- Joined:
Triggering event from xaml -> c++?
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>
-
-
sfernandez
Site Admin
- Posts: 2869
- Joined:
Re: Triggering event from xaml -> c++?
If I try to set a binding in the Button Click event I get this error in Noesis: "Unknown property 'Button.Click', or object to assign is incompatible".
Button Click event can only be set to a function from the code-behind class, not bindings.
Anyway, if you are trying to execute some code in your viewmodel you should take a look at commands. Basically you expose a command in your viewmodel and then bind to that object in the Command property of the Button:
Button Click event can only be set to a function from the code-behind class, not bindings.
Anyway, if you are trying to execute some code in your viewmodel you should take a look at commands. Basically you expose a command in your viewmodel and then bind to that object in the Command property of the Button:
Code: Select all
<Button Command="{Binding CloseCommand}">Close</Button>
-
- realm_mike
- Posts: 5
- Joined:
Re: Triggering event from xaml -> c++?
Aha. I had overlooked 'commands', this seems to work fine for triggering events like this. Thanks!
Who is online
Users browsing this forum: No registered users and 0 guests