Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>For a XAML windows store app, the default look-and-feel of controls is defined in <code>Common/StandardStyles.xaml</code>. If you've ever looked at that file, you'll notice a ton of references like <code>{StaticResource ApplicationForegroundThemeBrush}</code>. Looks promising... </p> <p>Unfortunately, these "theme brushes" aren't defined anywhere in your app, and there's no easy way to set a light or dark override for individual controls. However, there is an answer.</p> <p>Fortunately, <a href="http://metro.excastle.com/xaml-system-brushes" rel="nofollow">there's an excellent blog post by Joe White</a> on the default theme colors, which <a href="https://www.dropbox.com/s/7pkxwgmgekh2v2q/ThemeColors.xml" rel="nofollow">I've turned into a resource dictionary that you can find here</a>. Dropbox only does xml previews so you'll have to rename the file.</p> <p>Copying these resources to your app won't help by itself though. To make use of them, you need to surgically override the default control styles to use them!</p> <p>One way to do this is to create a new resource dictionary, e.g. at <code>Common/CustomStyles.xaml</code>, and merge that into the app's resources like so:</p> <pre><code>&lt;Application x:Class="My.App" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" RequestedTheme="Light"&gt; &lt;Application.Resources&gt; &lt;ResourceDictionary&gt; &lt;ResourceDictionary.MergedDictionaries&gt; &lt;!-- Styles that define common aspects of the platform look and feel Required by Visual Studio project and item templates --&gt; &lt;ResourceDictionary Source="Common/ThemeColors.xaml"/&gt; &lt;ResourceDictionary Source="Common/StandardStyles.xaml"/&gt; &lt;ResourceDictionary Source="Common/CustomStyles.xaml"/&gt; &lt;/ResourceDictionary.MergedDictionaries&gt; &lt;/ResourceDictionary&gt; &lt;/Application.Resources&gt; &lt;/Application&gt; </code></pre> <p>Notice that our default theme is <code>Light</code>. If we'd like to make a <code>Dark</code>-themed <code>TextBlock</code>, let's copy the visual style from <code>StandardStyles.xaml</code> and add it to our <code>CustomStyles.xaml</code> and make a few changes.</p> <pre><code>&lt;Style x:Key="BasicRichTextStyleDark" TargetType="RichTextBlock"&gt; &lt;Setter Property="Foreground" Value="{StaticResource ApplicationForegroundThemeBrushDark}"/&gt; &lt;Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}"/&gt; &lt;Setter Property="FontFamily" Value="{StaticResource ContentControlThemeFontFamily}"/&gt; &lt;Setter Property="TextTrimming" Value="WordEllipsis"/&gt; &lt;Setter Property="TextWrapping" Value="Wrap"/&gt; &lt;Setter Property="Typography.StylisticSet20" Value="True"/&gt; &lt;Setter Property="Typography.DiscretionaryLigatures" Value="True"/&gt; &lt;Setter Property="Typography.CaseSensitiveForms" Value="True"/&gt; &lt;/Style&gt; </code></pre> <p><strong>Notice that we have appended <code>Dark</code> to the style name and the theme brush definitions!</strong> You can do this via find and replace <code>"ThemeBrush}"</code> => <code>"ThemeBrushDark}"</code> in your CustomStyles.xaml file.</p> <p>Now you can create a dark-themed text block like so:</p> <pre><code>&lt;TextBlock Style="{StaticResource BasicRichTextStyleDark}"/&gt; </code></pre> <p>Of course, you can use this technique for any other type of control as well. A little tedious, but the results are correct and it's not nearly as bad as trying to define every color manually!</p> <p><strong>There's no magic here.</strong> We're just defining some colors and overriding a default style with one that we copy-pasted and modified to use our colors.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload