0

I have a horizontal ListView where I would like to handle the scrolling differently than the usual scrollbar.

Right now a scrollbar appears when the items overflow. Instead I would like to detect this and add buttons on each side to do the scrolling, just as browsers do.

<ListView Grid.Column="1"
               Name="NavList"
               ItemsSource="{x:Bind TabItems}"
               ScrollViewer.HorizontalScrollBarVisibility="Auto"
               ScrollViewer.HorizontalScrollMode="Enabled" 
               ScrollViewer.VerticalScrollMode="Disabled"
               IsItemClickEnabled="True"
               ItemClick="NavList_OnItemClick"
               ItemContainerStyle="{StaticResource ListViewItemStyleCustom}"
               SizeChanged="NavList_OnSizeChanged">
               <ListView.ItemTemplate>
                   <DataTemplate x:DataType="models:TabNavigationItem">
                       <Grid Height="48" Margin="4,0,4,0">
                           <Grid.ColumnDefinitions>
                               <ColumnDefinition Width="*"/>
                               <ColumnDefinition Width="Auto"/>
                           </Grid.ColumnDefinitions>
                           <TextBlock Grid.Column="0" Height="20" Text="{x:Bind Text}" HorizontalAlignment="Stretch" VerticalAlignment="Center" TextTrimming="CharacterEllipsis"></TextBlock>
                            <Viewbox Grid.Column="1" Width="14" Height="14" HorizontalAlignment="Right" VerticalAlignment="Center" Margin="2,1,0,0" Visibility="{x:Bind Selected, Mode=OneWay}">
                                <Button Width="100" Height="100" Background="{StaticResource Transparent}" VerticalAlignment="Center" Click="TabCloseButton_OnClick" Padding="0,0,0,0" HorizontalContentAlignment="Right">
                                    <FontIcon FontFamily="Segoe MDL2 Assets" Glyph="&#xE711;" FontSize="100" Foreground="{StaticResource Text-Black}"></FontIcon>
                                </Button>
                            </Viewbox>
                        </Grid>
                    </DataTemplate>
                </ListView.ItemTemplate>
                <ListView.ItemsPanel>
                    <ItemsPanelTemplate>
                        <controls:WrapPanel HorizontalSpacing="0" Orientation="Horizontal" Height="48"></controls:WrapPanel>
                    </ItemsPanelTemplate>
                </ListView.ItemsPanel>
</ListView>

My ListView. It starts after the "Home"-button and ends at the "Search"-button:

My ListView with standard scrollbar

The functionality I want:

Firefox tab view

Can someone point me in a direction of how to achieve this?

1
  • 1
    What I would do in this situation is create a custom class that inherits from Panel or StackPanel that handles when the buttons should appear and the scrolling and use it in the <ItemsPanelTemplate> instead of the WrapPanel Commented Jan 17, 2019 at 11:29

1 Answer 1

3

What you need actually is a TabView control. Please check the document to learn how to use it.

enter image description here

It's open source, you could check its source code for further study.

Sign up to request clarification or add additional context in comments.

3 Comments

I have tried the TabView control but it lacks some basic functionality, such as being able to not having a tab selected and detecting when a tab is clicked. I am handling all navigation myself, so the TabView does not really fit.
@Anddev That's the reason why I tell you to see its source code. If you check TabView's source code, you would see that it inherits from ListViewBase class. This means that it has ItemClick event. It should be that you want. But, please note that, you need to set IsItemClickEnabled="True", then the ItemClick event will be fired when you click the tab.
I see - thank you! Do you know how I would be able to not have any tabs selected?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.