Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 89864

How to bind the selected tab?

$
0
0

Hello:

I don't know why, but binding is still elusive to me to learn.
I need to navigate between tabs using buttons inside of the pages, so I though that the best way to do it is to create a variable in my ViewModel, and bind the "currentPage" tab property to it.
Ok, the problem is... I don't know how to make the binding.

I looked about three hours on the Internet, and the best approach that I saw was to create a BindableTabbedPage, but I think it was too much for what I need to do.
For the record, this is my TabbedPage:

```public class NewReceiptDocFilterTabbedPage : TabbedPage
{
private NewReceiptDocFilterViewModel filterViewModel;
private NewReceiptDocFilterFilterPage filterPage;
private NewReceiptDocFilterSelectionPage selectionPage;
//private NewReceiptDocFilterAddedPage addedPage;

    public NewReceiptDocFilterTabbedPage (INavigation mainNavigation)
    {
        filterViewModel = new NewReceiptDocFilterViewModel() { Navigation = mainNavigation };
        filterPage = new NewReceiptDocFilterFilterPage() { BindingContext = filterViewModel, Title = TextResources.NewReceipt_TabFilter } ;
        selectionPage = new NewReceiptDocFilterSelectionPage() { BindingContext = filterViewModel, Title = TextResources.NewReceipt_TabSelection };

        Children.Add(filterPage);
        Children.Add(selectionPage);

        CurrentPage.SetBinding(TabbedPage.SelectedItemProperty, new Binding("selectedTab", source: filterViewModel)); //the binding should be here, right?
    }
}```

And this is my variable inside the ViewModel:
private int _selectedTab; public int selectedTab { get { return _selectedTab; } set { _selectedTab = value; OnPropertyChanged(() => selectedTab); } }

Sorry for so noob question, but I can't get it working, and I'm pretty sure that I'm missing a small piece of information that I can't find.
Thank you.


Viewing all articles
Browse latest Browse all 89864

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>