简体   繁体   English

Xamarin Forms UWP 更改垂直滚动条颜色

[英]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). 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?也许可以从 UWP App.xamlApp.xaml.cs以某种方式做到这一点?

Maybe is possible to do it from UWP App.xaml or App.xaml.cs somehow也许可以从 UWP App.xaml 或 App.xaml.cs 以某种方式做到这一点

Sure, you could edit the UWP native ScrollBar style to update the default ScrollBar interface.当然,您可以编辑 UWP 原生 ScrollBar 样式来更新默认 ScrollBar 界面。 And the following code is updating the thumb's color.下面的代码正在更新拇指的颜色。 you could copy the following to your uwp app.xaml file directly您可以将以下内容直接复制到您的 uwp app.xaml 文件中

<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.您需要编辑 UWP 项目中的 app.xaml,而不是共享代码项目中的 app.xaml。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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