Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XAML UWA Scrollbar not showing

Tags:

c#

uwp-xaml

In the following code the Scrollbar control does not display but the Slider control does. If I change the Scrollbar control to a Slider control simply by changing Scrollbar to Slider it works perfectly, however I would prefer the look of the scrollbar control over the slider for the application.

I'm manually drawing a large 1000 cell x 1000 cell grid using Win2D into the animated canvas, but only displaying the part scrolled into by using the scrollbar (slider) positions.

Works perfectly when using the Slider controls.

<Page
x:Class="TrappedEditor.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:TrappedEditor"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:canvas="using:Microsoft.Graphics.Canvas.UI.Xaml"
Unloaded="Page_Unloaded"
mc:Ignorable="d">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" SizeChanged="Grid_SizeChanged">
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="1*"/>
            <ColumnDefinition Width="50"/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="*"/>
            <RowDefinition Height="50"/>
        </Grid.RowDefinitions>
        <ScrollBar x:Name="scrollBarVertical" Visibility="Visible" Grid.Row="0" Grid.Column="1" ValueChanged="scrollBarVertical_ValueChanged" Orientation="Vertical" Minimum="0" Maximum="1000"/>
        <Slider x:Name="scrollBarHorizontal" Grid.Column="0" Grid.ColumnSpan="2" Grid.Row="1" Orientation="Horizontal" ValueChanged="scrollBarHorizontal_ValueChanged" Minimum="0" Maximum="1000"/>
        <canvas:CanvasAnimatedControl Grid.Row="0" Grid.Column="0" x:Name="canvas" Draw="canvas_Draw" CreateResources="canvas_CreateResources"/>
    </Grid>

like image 315
fikeus Avatar asked Nov 08 '22 12:11

fikeus


1 Answers

Worked this out. Adding IndicatorMode="MouseIndicator" displays the ScrollBar as expected.

eg:

<ScrollBar x:Name="scrollBarVertical" IndicatorMode="MouseIndicator" Visibility="Visible" Grid.Row="0" Grid.Column="1" ValueChanged="scrollBarVertical_ValueChanged" Orientation="Vertical" Minimum="0" Maximum="1000"/>
like image 133
fikeus Avatar answered Nov 14 '22 21:11

fikeus