Hi ppl! ToolbarItems.Add(new ToolbarItem("Save", null, () => (BindingContext as AddPersonViewModel).SaveCommand.Execute(null)));
so that my toolbar item code. each time i press the save btn then savecommand.execute! i want to add one more command to this button. i would like its time i click the button 1st to save the data and then to navigate to anothe page ! How can i do that? Thanks
You can only assign one command to a toolbaritem.
What your proposing isn't a good idea though as I'm presuming you'd only want to navigate if the save was successful.
You'd be better calling a method in your view model that does the save and then calls the navigation action in the same relaycommand, it's much more manageable.
@NMackay @WinterCloud it works (one command pointing to Method1, and Method1 calls Method2,3,4) thanks guys!
Answers
@EBatik
You can only assign one command to a toolbaritem.
What your proposing isn't a good idea though as I'm presuming you'd only want to navigate if the save was successful.
You'd be better calling a method in your view model that does the save and then calls the navigation action in the same relaycommand, it's much more manageable.
You can however execute a bound command and raise a clicked event and both will fire but it seems wrong, your executing code in your view model and code behind with no way of controlling in what order the code will execute.
@NMackay
thank you for your reply! I ill try the way you discribed in the first comment and i ll let you know.
@NMackay my code fails ofc!
how can i create a command inside a command?Could you help me with that!?
@EBatik
You could just create a second command in your viewmodel and execute it from the command bound to your control if you want to go down that path.
Here's an example but I don't see why you'd want to do that.
@NMackay are you using xlabs?
No, I don't use XLabs.
Why two commands? Any benefits of doing this?
Why not just one command pointing to Method1, and Method1 calls Method2,3,4....?
@WinterCloud
Exactly, there is no benefit. That was my 1st comment.
Oh, sorry I went straight to code.
@NMackay @WinterCloud it works (one command pointing to Method1, and Method1 calls Method2,3,4) thanks guys!