Overwrite SurfaceColor Resources

I saw many times on the Surface Application Design and Development Forums questions asking how to change the aspect of Surface Controls, unfortunately  mostly I saw answer where it is suggested to extract the template of the control.

Event if this is a correct approach for almost all WPF standard controls if you apply this pattern to a Surface control the color you customize using this approach will be reset if the administrator selects a new color scheme while your application is running.

Correct Approach is to overwrite SurfaceColor resources  using SurfaceColors class, let’s see how.

Suppose that you want to change the LibraryBar control background to transparent, in this case you have to overwrite the LibraryControlScrollAreaBackgroundBrushKey basically you have to create your own resurce dictionay like the one below:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="http://schemas.microsoft.com/surface/2008"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup compatibility/2006"
                    mc:Ignorable="d">
    <SolidColorBrush x:Key="{x:Static s:SurfaceColors.LibraryControlScrollAreaBackgroundBrushKey }" Color="Transparent" />
</ResourceDictionary>

then you have to include in in your App.xaml like below:

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:s="http://schemas.microsoft.com/surface/2008"
                    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                    mc:Ignorable="d">
    <SolidColorBrush x:Key="{x:Static s:SurfaceColors.LibraryControlScrollAreaBackgroundBrushKey

And here we go, if you launch your app all you Library control will have a transparent background.

 

Ultimi Post

Discalmer

Articles and content of this blog aren't and shouldn't be interpreted as professional advice or opinions. Author writes on a personal basis and as part of their own research, experimentation and knowledge. Opinions expressed aren't in any way attributable to professional affiliations / institutional thereof or to opinions that the author express as part of their roles / positions that may be quite different from that reported here.