Search code examples
c#uwptabview

UWP Tab View not responding


I have a page with a Tab View. Inside every tab is another page. Whenever I try to interact with the tab, nothing works. I tried interacting with it with SettingsPage as the content, and it worked.

MainPage - contains the tabs

TabbedMainPage - contains the workspace

SettigsPage - contains settings

MainPage:

    private void TabView_AddTabButtonClick(TabView sender, object args)
    {
        sender.TabItems.Add(CreateNewTab());
    }

    public TabViewItem OpenSettingsTab()
    {
        TabViewItem newItem = new TabViewItem();
        newItem.Header = "Settings";
        newItem.IconSource = new Microsoft.UI.Xaml.Controls.SymbolIconSource() { Symbol = Symbol.Setting };
        Frame frame = new Frame();
        frame.Navigate(typeof(SettingsPage));
        newItem.Content = frame;
        TabbedView.UpdateLayout();
        return newItem;
    }

    public void CreateSettingsTab()
    {
        TabbedView.TabItems.Add(OpenSettingsTab());
        TabbedView.UpdateLayout();
        TabbedView.SelectedIndex = TabbedView.TabItems.Count - 1;
    }

    public TabViewItem CreateNewTab()
    {
        TabViewItem newItem = new TabViewItem();
        newItem.Header = "New Tab";
        newItem.IconSource = new Microsoft.UI.Xaml.Controls.SymbolIconSource() { Symbol = Symbol.Document };
        Frame frame = new Frame();
        frame.Navigate(typeof(TabbedMainPage));
        newItem.Content = frame;
        TabbedView.UpdateLayout();
        return newItem;
    }

    private void TabbedView_Loaded(object sender, RoutedEventArgs e)
    {
        var S = sender as TabView;
        if (S.TabItems.Count == 0)
        {
            S.TabItems.Add(CreateNewTab());
        }
        TabbedView.UpdateLayout();
    }

TabbedMainPage has the following components: ColorPicker, DropDownButton, MenuBar, Border, Button, CheckBox, ComboBox, Flyout, Grid, Image, MenuFlyout, Pivot, PivotItem, StackPanel, TextBlock, TextBox, Flyout, Popup, RichEditBox, ScrollViewer, Slider, ToggleButton and Tooltip.

I think it might be caused by overloading with components, but I'm not sure. I also have these in my code:

    MediaElement ME;

    SpeechSynthesizer Synth;

    public StorageFile TXTFile;

    public IRandomAccessStream RAS;

    private readonly PrintHelperOptions PP = new PrintHelperOptions();

    var LS = ApplicationData.Current.LocalSettings;

    var TB = ApplicationView.GetForCurrentView().TitleBar;

    var CTB = CoreApplication.GetCurrentView().TitleBar;

Solution

  • I managed to fix the bug by removing the Pivot from the toolbar. It was interfering with the tab functionality, so I merged all the items together.