简体   繁体   中英

Xamarin Forms UWP change vertical scrollbar color

I have a Xamarin Forms app which I'd like to change the UWP vertical scrollbar color (currently it uses the default windows color).

How can I do it?

Maybe is possible to do it from UWP App.xaml or App.xaml.cs somehow?

Maybe is possible to do it from UWP App.xaml or App.xaml.cs somehow

Sure, you could edit the UWP native ScrollBar style to update the default ScrollBar interface. And the following code is updating the thumb's color. you could copy the following to your uwp app.xaml file directly

<Application.Resources>
        <ResourceDictionary>
            <SolidColorBrush x:Key="ScrollBarBackgroundBrush" Color="RoyalBlue" />
            <SolidColorBrush x:Key="ScrollBarPanningThumbBackground" Color="RoyalBlue" />
            <SolidColorBrush x:Key="ScrollBarThumbFillPressed" Color="RoyalBlue" />
            <SolidColorBrush x:Key="ScrollBarThumbFillPointerOver" Color="RoyalBlue" />
            <SolidColorBrush x:Key="ScrollBarThumbFill" Color="RoyalBlue" />

<!--The default scrollbar is too long to share here, please go to UWP generic.xaml to find the defalut `ScrollBar` style and edit base on that.-->

         <Style TargetType="ScrollBar">
                <Setter Property="MinWidth" Value="{ThemeResource ScrollBarSize}" />
                <Setter Property="MinHeight" Value="{ThemeResource ScrollBarSize}" />
                <Setter Property="Background" Value="{ThemeResource ScrollBarBackground}" />
                <Setter Property="Foreground" Value="{ThemeResource ScrollBarForeground}" />
                <Setter Property="BorderBrush" Value="{ThemeResource ScrollBarBorderBrush}" />
                <Setter Property="IsTabStop" Value="False" />
                <Setter Property="Template">

           ........

      </ResourceDictionary>
    </Application.Resources>

The accepted solution works. I was a little stuck, so putting it out there (in hindsight it was obvious). You need to edit the app.xaml in the UWP project, NOT the app.xaml in the shared code project.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM