Xamarin.Forms: Switching TabbedPage Tabs Programmatically
Sometimes, your app uses tabs to separate different user activities. Sometimes, though, those activities aren’t completely independent. When that happens, you need an action in one tab to cause the user to switch to another tab. I’ll show you how to do that in code using Xamarin.Forms. In case you haven’t already started your tabs, we’ll start from the beginning. (Note: while the UI parts can be done quite well in XAML, this post will do it all in code.) First, Some Tabs Just in case you haven’t already made your Xamarin.Forms tab system, we’ll start there. This is as simple as using an instance of TabbedPage. Since we will want a little more control over things going forward, let’s create a subclass inheriting from it. public class MainTabbedPage : TabbedPage { public MainTabbedPage() { Children.Add(new somePage()); Children.Add(new someOtherPage()); } } You simply make this the MainPage in your App, now, and you get tabs. public class App : Application { public App() { MainPage = new MainTabbedPage(); } } If you run your app at this point, though, you’ll notice something fairly obvious missing from your tabs. No titles, no icons. In fact, on iOS, you can’t even tell… Continue reading