![](/img/trans.png)
[英]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.