1

When there are no tab items displayed, or none are selected, Microsoft.Toolkit.Uwp.UI.Controls.TabView displays a blank canvas.

How can I modify this?

TabView doesn't seem to have a Content Property?

EDIT:

looks like this is not straightforward:

https://github.com/windows-toolkit/WindowsCommunityToolkit/blob/master/Microsoft.Toolkit.Uwp.UI.Controls/TabView/TabView.cs

ln 164

...
            if (_tabContentPresenter != null)
            {
                if (SelectedItem == null)
                {
                    _tabContentPresenter.Content = null;
                    _tabContentPresenter.ContentTemplate = null;
                }
                else
                {
                    if (ContainerFromItem(SelectedItem) is TabViewItem container)
                    {
                        _tabContentPresenter.Content = container.Content;
                        _tabContentPresenter.ContentTemplate = container.ContentTemplate;
                    }
                }
            }
...
compound eye
  • 1,898
  • 18
  • 23

1 Answers1

2

If you want to set a default view for TabView when it doesn't have any tab, you can set the default view manually and then place the default view above TabView to cover its content area. When there is no tab, you can set the Visibility of the view as Visible to show it. It is not recommended to modify the tabView itself to achieve it. For example, MyDefaultView below is the default content I set.

.xaml:

<Grid>
    <controls:TabView x:Name="MyTabView" TabItemsSource="{x:Bind Lists,Mode=OneWay}">
    </controls:TabView>

    <StackPanel Background="AliceBlue" Margin="0,40,0,0" x:Name="MyDefaultView">
        <Image Source="Assets/StoreLogo.png" Width="300" Height="300"></Image>
        <TextBlock TextAlignment="Center">welcome, please add tabs</TextBlock>
    </StackPanel>
</Grid>

.cs:

if (Lists.Count > 0)
{
    MyDefaultView.Visibility = Visibility.Collapsed;
}
else 
{
    MyDefaultView.Visibility = Visibility.Visible;
}
Faywang - MSFT
  • 5,798
  • 1
  • 5
  • 8