Connect command in view model to custom property
Posted: 03 Jul 2024, 22:54
hi,
i need another help with my custom control:
the bold part (settings_button_click event) is working (i used NS_CONNECT_ATTACHED_EVENT)
i want to make the underline part (microscope_button_click) to work by creating a delegate command on view model and bind it to the event, i am not sure my syntax is actually correct.
declaration and reflection of the event was done :
definition also in other part.
my view model i definde the command in the constructoe with callback defined late and reflect:
i saw something in tutorials like this:
but i could not make it work (using the Interaction + Triggers) and i was told that it should be much easier and by the first way i tried.
thanks again for the help.
i need another help with my custom control:
Code: Select all
<local:SettingsUserControl
x:Name="SettingModule" Background="Transperent" Grid.Row="1" Grid.Column="0" Margin="10"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch" IsVisibleControlProperty="True"
SettingsButtonShadedProperty="True"
[u] microscope_button_click = "{Binding Microscope_Button_Click_Command}[/u]"
[b] settings_button_click = "SettingsUserControl_OnSettingsButtonClick"[/b]>
</local:SettingsUserControl>i want to make the underline part (microscope_button_click) to work by creating a delegate command on view model and bind it to the event, i am not sure my syntax is actually correct.
declaration and reflection of the event was done :
Code: Select all
static const Noesis::RoutedEvent* power_button_clickEvent;
data->RegisterEvent(power_button_clickEvent, "power_button_click", Noesis::RoutingStrategy_Bubble);my view model i definde the command in the constructoe with callback defined late and reflect:
Code: Select all
MainWindowViewModel::MainWindowViewModel()
{
mMicroscopeButtonCommand = Noesis::MakePtr<NoesisApp::DelegateCommand>(MakeDelegate(this, &MainWindowViewModel::onMicroscopeButtonPress));
}
NoesisApp::DelegateCommand* MainWindowViewModel::getMicroscopePressButtonCommand() const
{
return mMicroscopeButtonCommand;
}
void MainWindowViewModel::onMicroscopeButtonPress(Noesis::BaseComponent *param_)
{
std::cout << "\nView Model Microscope Button Pressed\n" << std::endl;
}
NS_IMPLEMENT_REFLECTION(BasicAssistantScreen::MainWindowViewModel, "BasicAssistantScreen.MainWindowViewModel")
{
NsProp("MyCommand", &MainWindowViewModel::getMicroscopePressButtonCommand);
}Code: Select all
<Grid
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:b="http://schemas.microsoft.com/xaml/behaviors">
<Button Content="Close">
<b:Interaction.Triggers>
<b:EventTrigger EventName="Click">
<b:InvokeCommandAction Command="{Binding CloseCommand}" CommandParameter="Force"/>
</b:EventTrigger>
</b:Interaction.Triggers>
</Button>
</Grid>thanks again for the help.