uwp
Teman resurser
Sök…
Syntax
- C #: Application.Current.Resources ["yourColorKey"]
- Xaml: {ThemeResource yourColorKey}
parametrar
| Parameter | Ändamål |
|---|---|
yourColorKey | En nyckel du ger för att få tillbaka ett Color . Det skiljer sig mellan C # och Xaml |
Anmärkningar
Med UWP kan du ta full kontroll över fördelarna med Windows 10. Vissa av dessa fördelar är grafiska, som Accent-färgen eller Dark / Light-teman.
För att förbereda din app för att vara kompatibel med dessa funktioner har ett gäng förfärgade färger implementerats i UWP för att ändra med Accent-färgen på OS som programmet körs på, eller med användarens temaval.
Det finns två "sätt" att göra detta:
Diretly i Xaml med
Color = {ThemeResource x}attribut (eller vilket attribut som tar enBrushsom värde, som BorderBrush, bakgrund etc.)I C # -kod bakom, genom att söka efter färgen i Resource-katalogen för den aktuella appen. Detta ger ett
Color, så om du vill placera det iColorför ett objekt du refererade från din Xaml, måste du göra en ny borste så här:
new SolidColorBrush(Application.Current.Resources["yourColorKey"])
För en referens av färgnycklar i c #, vänligen kontakta:
https://msdn.microsoft.com/windows/uwp/controls-and-patterns/xaml-theme-resources
Tillgång till temaressurser i Xaml
Utdrag från MyExampleFile.xaml
<TextBlock Foreground="{ThemeResource SystemControlBackgroundAccentBrush}"
Text="This is a colored textbox that use the Accent color of your Windows 10"/>
<TextBlock Foreground="{ThemeResource SystemControlBackgroundBaseHighBrush}"
Text="This is a colored textbox that use a color that is readable in both Light and Dark theme"/>
Tillgång till temaressurser i C #
Utdrag från MyExampleFile.xaml
<TextBlock x:Name="MyTextBlock"
Text="This is a TextBlock colored from the code behind"/>
Utdrag från MyExampleFile.xaml.cs
// We use the application's Resource dictionary to get the current Accent of your Windows 10
MyTextBlock.Color = new SolidColorBrush(Application.Current.Resources["SystemAccentColor"]);