BartekW
Topic Author
Posts: 53
Joined: 24 Mar 2021, 14:33

Command binding doens't work C++

05 May 2021, 10:36

Hey, I made method and NsProp'ed this, then I use command in .xaml and I was surprised becouse it didn't work.
Could you help?
Test::Test()
{
	_backClicked.SetExecuteFunc(MakeDelegate(this, &Test::OnBack));

	Initialized() += MakeDelegate(this, &Test::OnInitialized);

	InitializeComponent();	
}

////////////////////////////////////////////////////////////////////////////////////////////////////
void Test::InitializeComponent()
{
	GUI::LoadComponent(this, "Test.xaml");	
}

void OurMenu::Test::OnInitialized(Noesis::BaseComponent *, const Noesis::EventArgs &)
{
	rootContent = FindName<ContentControl>("RootContent");
}

const NoesisApp::DelegateCommand * OurMenu::Test::GetBackDelegate() const
{
	return &_backClicked;
}


void OurMenu::Test::OnBack(BaseComponent * param)
{
	NS_UNUSED(param);
	MessageBox(0, 0, "Back", 0);
}

////////////////////////////////////////////////////////////////////////////////////////////////////
NS_BEGIN_COLD_REGION

NS_IMPLEMENT_REFLECTION(OurMenu::Test, "OurMenu.Test")
{
	NsProp("OnBack", &Test::GetBackDelegate);
	NS_UNUSED(helper);
}
And this is what I have in Button
<i:Interaction.Triggers>
                        <i:EventTrigger EventName="KeyDown">
                            <i:InvokeCommandAction Command="{Binding OnBack}"/>
                        </i:EventTrigger>
                    </i:Interaction.Triggers>
Have u idea why?
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Command binding doens't work C++

05 May 2021, 10:58

It seems you are missing the DataContext for the binding to work:
Test::Test()
{
	_backClicked.SetExecuteFunc(MakeDelegate(this, &Test::OnBack));

	Initialized() += MakeDelegate(this, &Test::OnInitialized);

	InitializeComponent();	
	
	SetDataContext(this);
}
 
BartekW
Topic Author
Posts: 53
Joined: 24 Mar 2021, 14:33

Re: Command binding doens't work C++

05 May 2021, 11:11

Okey I found a problem, I can't use second class to GUI::LoadComponent becouse it doesnt work :|
 
User avatar
sfernandez
Site Admin
Posts: 2984
Joined: 22 Dec 2011, 19:20

Re: Command binding doens't work C++

05 May 2021, 11:19

Okey I found a problem, I can't use second class to GUI::LoadComponent becouse it doesnt work :|
I don't understand, could you please elaborate what is not working.
 
User avatar
jsantos
Site Admin
Posts: 3906
Joined: 20 Jan 2012, 17:18
Contact:

Re: Command binding doens't work C++

05 May 2021, 11:48

Our Buttons example uses Command binding. Please, use that example as reference.

Closing this.

Who is online

Users browsing this forum: Bing [Bot] and 7 guests