[英]How do I change the accent colour of a Xamarin.Forms UWP application?
I am developing a Xamarin.Forms
UWP application.我正在开发一个
Xamarin.Forms
UWP 应用程序。
I am struggling to set the accent colour of my application.我正在努力设置我的应用程序的强调色。 This is the colour that is used for certain behaviors by default on controls.
这是默认情况下在控件上用于某些行为的颜色。
For example the Entry control has a default blue highlighting on focus shown below:例如,Entry 控件在焦点上有一个默认的蓝色突出显示,如下所示:
I have tried a few suggestions from this thread: Change Accent Color in Windows 10 UWP but none seemed to work.我已经尝试了这个线程的一些建议: 在 Windows 10 UWP 中更改强调色,但似乎都没有用。
I am not sure whether it is because I didn't fully understand how changing the colour for UWP differs for Xamarin.UWP, or whether what I'm trying to do is even possible with Xamarin.Forms.我不确定是否是因为我没有完全理解 UWP 的颜色更改与 Xamarin.UWP 有何不同,或者我正在尝试做的事情是否甚至可以用于 Xamarin.Forms。
Has anyone found out how to do this?有没有人知道如何做到这一点?
Here is the style code of FormsTextBox for UWP. 这是UWP的FormsTextBox的样式代码。
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: 因此,要更改文本框边框画笔的颜色,您可以将这些
ThemeResources
添加到App.xaml
如下所示:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="SystemControlHighlightAccentBrush" Color="#ff0000" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Application.Resources>
You can define a style setter property in App.xaml 您可以在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 然后使用CustomRenderer来更改颜色所需的控件
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.
此代码可用于在Xamarin的控件上具有本机样式。
The absolute easiest way is to go to the styles.xml file which is located in Resources/values and uncomment:绝对最简单的方法是将 go 转到位于 Resources/values 中的styles.xml文件并取消注释:
<item name="colorAccent">#FF2081</item>
This changes the accent color on the whole project eg with Entrys.这会改变整个项目的强调色,例如条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.