benruehl / adonis-ui

Lightweight UI toolkit for WPF applications offering classic but enhanced windows visuals
https://benruehl.github.io/adonis-ui/
MIT License
1.71k stars 143 forks source link

Can't copy ColorSchemes/Light.xaml into my app because ResourceAliasExtension class is internal #49

Closed dbruning closed 4 years ago

dbruning commented 4 years ago

(thanks for your work on this excellent library!)

Describe the bug "Custom color schemes" documentation recommends creating a copy of Light.xaml and/or Dark.xaml to customize. However, Light.xaml uses AdonisUI.Helpers.ResourceAliasExtension is internal, so I can't reference it from outside the AdonisUI dll. This means I effectively can't have a customised copy of Light.xaml in my own app.

To Reproduce Steps to reproduce the behavior:

  1. Copy AdonisUI/ColorSchemes/Light.xaml from Github into your application
  2. Try to compile
  3. See error: LightThemeColors.xaml(18, 90): [MC3064] Only public or internal classes can be used within markup. 'ResourceAliasExtension' type is not public or internal.

Additional context Workaround is to create a copy of AdonisUI/Helpers/ResourceAliasExtension.cs in my own project - but would be nicer not to have to (i.e. if ResourceAliasExtension was a public class).

benruehl commented 4 years ago

I see this is kind of misleading, sorry for that. The ResourceAliasExtension should be either public or the docs should be more clear about how to create custom color schemes.

I'll try to explain it a little more detailed here.

If you want to create a whole new color scheme you can create a new ResourceDictionary file and add a new Color for each key in AdonisUI.Colors and a new Brush (e.g. SolidColorBrush) for each key in AdonisUI.Brushes. Don't forget to use AdonisUI's keys for all those resources, e.g.:

<Color x:Key="{x:Static adonisUi:Colors.AccentColor}">#0BAC08</Color>
<!-- all colors go here -->

<SolidColorBrush x:Key="{x:Static adonisUi:Brushes.AccentBrush}" Color="{DynamicResource {x:Static adonisUi:Colors.AccentColor}}"/>
<!-- all brushes go here -->

If you want to use a shipped color scheme and customize only some resources you can create a new ResourceDictionary file and make it include the theme you want to derive from in its ResourceDictionary.MergedDictionaries. Afterwards, you can create colors as you like and assign the color keys you want to override.

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:local="clr-namespace:AdonisUITest"
                    xmlns:adonisUi="clr-namespace:AdonisUI;assembly=AdonisUI">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/AdonisUI;component/ColorSchemes/Light.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Color x:Key="{x:Static adonisUi:Colors.AccentColor}">Green</Color>
    <!-- additional colors or brushes go here -->

</ResourceDictionary>

The colors and brushes you did not specify are then taken from the included color scheme. You can include this ResourceDictionary in your App.xaml instead of the light and dark color schemes or in addition to them if you want to switch between those.

So now regarding your question: The ResourceAliasExtension is only used for Layer0BorderColor (and the associated brush). You can now either leave this color as it is by including the light color scheme and simply not overriding it. Or you assign a new value to it like mentioned:

<Color x:Key="{x:Static adonisUi:Colors.Layer0BorderColor}">#404040</Color>

Hope this helps :)

dbruning commented 4 years ago

Yes that does help, thanks! I didn't think to use the Adonis Light.xaml as a MergedDictionary inside my own ColorScheme. That's much better than copying the whole thing.