Toolbar Buttons with Different fragments invoking all fragment events using Xamarin MvvmCross?

kishukishu INMember ✭✭

My application is like this,

MainActivity --> ToolBar added
under MainActivity --->3 fragments, those settings,actions and variables.
SettingsFragment and ActionsFragment are having Save and Cancel buttons in Toolbar (but Variables is having different buttons I don't have any issue with this VariablesFragment).
So these Save,Cancel button I am accessing from the each fragment like below,

`var toolbar = ((MainActivity)this.Activity).FindViewById(Resource.Id.toolbar);
var btnCancel = toolbar.FindViewById(Resource.Id.btnCancel);
btnCancel.Click += delegate {

        var btnSave = toolbar.FindViewById<Button>(Resource.Id.btnSave);
        btnSave.Click += delegate {

I am able to accessing the click events from two of fragments but the issue is,
SettingsFragment is having a navigation to ActionsFragment, here I am saving some data using Save Click event but initially action fired at SettingsFragment and coming to ActionsFragment. How can I differentiate this? It should be clear for each fragment.
I am using MVVMCross here is my code in Settings Fragment,

var btnSave = toolbar.FindViewById<Button>(Resource.Id.btnSave); btnSave.Click += delegate { ViewModel.SaveCommand.Execute(); }; private void ExecuteSaveCommand() { ShowViewModel<VariablesViewModel>(); }

And in Actions Fragment,

`var toolbar = ((MainActivity)this.Activity).FindViewById(Resource.Id.toolbar);
var btnSave = toolbar.FindViewById(Resource.Id.btnSave);

        btnSave.Click += delegate

//ViewModel code,
private void SaveCommand()
var listItem = new ListViewItem();
listItem.Title = Label;
listItem.SubTitle = Data;


So initially it is going to SettingsFragment and navigating to VariablesViewModel later invoking ActionsFragment but not navigating to SettingsViewModel.
Here I wanted to invoke Specific Fragment buttons not all fragments every time.I can not maintain separate buttons for each Fragment as I have many buttons and Fragments to manage here I explained with 3 fragments for better understanding.

Your help is appreciable, Thank you in advance.

Sign In or Register to comment.