[英]How do I make images show up in UWP version of my Xamarin.Forms application
[英]How do I change the accent colour of a Xamarin.Forms UWP application?
我正在开发一个Xamarin.Forms
UWP 应用程序。
我正在努力设置我的应用程序的强调色。 这是默认情况下在控件上用于某些行为的颜色。
例如,Entry 控件在焦点上有一个默认的蓝色突出显示,如下所示:
我已经尝试了这个线程的一些建议: 在 Windows 10 UWP 中更改强调色,但似乎都没有用。
我不确定是否是因为我没有完全理解 UWP 的颜色更改与 Xamarin.UWP 有何不同,或者我正在尝试做的事情是否甚至可以用于 Xamarin.Forms。
有没有人知道如何做到这一点?
这是UWP的FormsTextBox的样式代码。
您需要覆盖以下样式的颜色:
<Setter Property="Foreground" Value="{ThemeResource SystemControlForegroundBaseHighBrush}" />
<Setter Property="Background" Value="{ThemeResource SystemControlBackgroundAltHighBrush}" />
<Setter Property="BackgroundFocusBrush" Value="{ThemeResource SystemControlBackgroundChromeWhiteBrush}" />
<Setter Property="BorderBrush" Value="{ThemeResource SystemControlForegroundChromeDisabledLowBrush}" />
因此,要更改文本框边框画笔的颜色,您可以将这些ThemeResources
添加到App.xaml
如下所示:
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<SolidColorBrush x:Key="SystemControlHighlightAccentBrush" Color="#ff0000" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
</Application.Resources>
您可以在App.xaml中定义样式设置器属性
<ResourceDictionary>
<Style TargetType="Button" x:Name="myNewButtonStyle">
<Setter Property="Background" Value="{ThemeResource ButtonBackgroundThemeBrush}" />
</Style>
</ResourceDictionary>
然后使用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;
}
}
以类似的方式,您将能够使用主题资源字典键并应用。 此代码可用于在Xamarin的控件上具有本机样式。
绝对最简单的方法是将 go 转到位于 Resources/values 中的styles.xml文件并取消注释:
<item name="colorAccent">#FF2081</item>
这会改变整个项目的强调色,例如条目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.