How do I change the accent colour of a Xamarin.Forms UWP application?

前端 未结 2 661
迷失自我
迷失自我 2021-01-20 05:42

I am developing a Xamarin.Forms UWP application.

I am struggling to set the accent colour of my application. This is the colour that is used for certain

相关标签:
2条回答
  • 2021-01-20 06:31

    Here is the style code of FormsTextBox for UWP.

    You need to override below styled colors:

    <Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
    <Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}" />
    <Setter Property="BackgroundFocusBrush" Value="{ThemeResource SystemControlBackgroundChromeWhiteBrush}" />
    <Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}" />
    

    So to change the colour of your textbox boarder brush you can add these ThemeResources to your App.xaml like so:

    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.ThemeDictionaries>
                <ResourceDictionary x:Key="Light">
                    <SolidColorBrush x:Key="SystemControlHighlightAccentBrush" Color="#ff0000" />
                </ResourceDictionary>
            </ResourceDictionary.ThemeDictionaries>
        </ResourceDictionary>
    </Application.Resources>
    
    0 讨论(0)
  • 2021-01-20 06:42

    You can define a style setter property in App.xaml

        <ResourceDictionary>    
            <Style TargetType="Button" x:Name="myNewButtonStyle">
                <Setter Property="Background" Value="{ThemeResource ButtonBackgroundThemeBrush}" />
            </Style>
        </ResourceDictionary>
    

    Then use CustomRenderer for the controls you need to change colors

        protected override void OnElementChanged(ElementChangedEventArgs<Button> e)
        {
            base.OnElementChanged(e);
            if (this.Element != null)
            {
                this.Control.Style = Windows.UI.Xaml.Application.Current.Resources["myNewButtonStyle"] as Windows.UI.Xaml.Style;
            }
        }
    

    in a similar way you would be able to use Themed Resource Dictionary key and apply. This code can be used to have native styles on Xamarin's control.

    0 讨论(0)
提交回复
热议问题