problem in Register command
Posted: 19 Mar 2018, 04:22
I want to register a custom command in UserControl, I implement it in WPF, but not work C++, some advices?
Code: Select all
//command in WPF
public static readonly DependencyProperty ButtonActionCommandProperty = DependencyProperty.Register(
"Command", typeof(ICommand), typeof(TouchButton), new UIPropertyMetadata(null));
public ICommand Command
{
get { return (ICommand)GetValue(ButtonActionCommandProperty); }
set { SetValue(ButtonActionCommandProperty, value); }
}
Code: Select all
//Register command
/*UIData->RegisterProperty<Ptr<BaseCommand>>(CommandProperty, "Command",
FrameworkPropertyMetadata::Create(Ptr<BaseCommand>(), FrameworkOptions_None));*/
UIData->RegisterProperty<Ptr<BaseCommand>>(CommandProperty, "Command",
UIPropertyMetadata::Create(Ptr<BaseCommand>()));
/*UIData->RegisterProperty<Ptr<BaseComponent>>(CommandParameterProperty, "CommandParameter",
FrameworkPropertyMetadata::Create(Ptr<BaseComponent>(), FrameworkOptions_None));*/
UIData->RegisterProperty<Ptr<BaseComponent>>(CommandParameterProperty, "CommandParameter",
UIPropertyMetadata::Create(Ptr<BaseComponent>()));
//Implemtent ICommand interface
Noesis::ICommand* TouchButton::GetCommand() const
{
//return nullptr;
return DependencyObject::GetValue<Ptr<ICommand>>(CommandProperty).GetPtr();
}
void GameGUI::TouchButton::SetCommand(BaseCommand* InCommand)
{
DependencyObject::SetValue<Ptr<BaseCommand>>(CommandProperty, InCommand);
}
Noesis::BaseComponent* TouchButton::GetCommandParameter() const
{
return DependencyObject::GetValue<Ptr<BaseComponent>>(CommandParameterProperty).GetPtr();
}
void TouchButton::SetCommandParameter(BaseComponent* InParam)
{
DependencyObject::SetValue<Ptr<BaseComponent>>(CommandParameterProperty, InParam);
}
//Fire command
if (GetCommand())
{
//this line is called
GetCommand()->Execute(GetCommandParameter());
}