[C++] Using commands
Posted: 25 Jan 2017, 08:19
Command function doesn't call. Can't find solution.
XAML:
Source code:
XAML:
Code: Select all
<Button x:Name="button1" Content="open project" Command="{Binding ButtonClick}"/> Code: Select all
class DelegateCommand : public BaseCommand {
public:
typedef Delegate<void(BaseComponent*)> Action;
DelegateCommand(const Action& action) : BaseCommand(NsSymbol::Null(), 0), _action(action) {}
NsBool CanExecute(BaseComponent* param) const {
return true;
}
void Execute(BaseComponent* param) const {
_action(param);
}
private:
Action _action;
NS_IMPLEMENT_INLINE_REFLECTION(DelegateCommand, BaseCommand) {
NsMeta<TypeId>("DelegateCommand");
}
}; Code: Select all
class ProjectSelect : public BaseComponent {
public:
ProjectSelect() {
mCommand = *new DelegateCommand(MakeDelegate(this, &ProjectSelect::ButtonClick));
}
void ButtonClick(BaseComponent* sender) {
// <<== Never access this point !!! =======
}
DelegateCommand* GetButtonClickCommand() const {
return mCommand.GetPtr();
}
private:
Ptr<DelegateCommand> mCommand;
NS_IMPLEMENT_INLINE_REFLECTION(ProjectSelect, BaseComponent) {
NsMeta<TypeId>("ProjectSelect");
NsProp("ButtonClick", &ProjectSelect::GetButtonClickCommand);
}
};