Hello,
Shell do not have APIs which tab was last selected.
If viewmodels for tabs are similar. You can create a view model that single instance.
public static class VMInstance
{
private static SampleViewModel _sampleViewModel = new SampleViewModel();
public static SampleViewModel SingleVM
{
get
{
return _sampleViewModel;
}
}
}
public class SampleViewModel: INotifyPropertyChanged
{
public string _name="test";
public string Name
{
set
{
if (_name != value)
{
_name = value;
OnPropertyChanged("Name");
}
}
get
{
return _name;
}
}
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public SampleViewModel()
{ }
}
Please bind the same viewmodel in the layout background code.
public Tab1Page()
{
InitializeComponent();
BindingContext = VMInstance.SingleVM;
}
public Tab2Page()
{
InitializeComponent();
BindingContext = VMInstance.SingleVM;
}
Then binding the same property for controls in the content pages of tab. If this value of property changed, all of pages will be changed.
For example, I binding Name
property's Text in tabs pages. when name changed in tab1, tab2 will be changed as well.
<Label
Text="{Binding Name}"
/>
Best Regards,
Leon Lu
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.