How do i override inherited XAML Classes?

Themes, Shared, and Core Libraries for Avalonia Forum

Posted 5 days ago by Ben Evans - Mr, Viper Applied Science
Version: 25.2.1
Avatar

I am having an issue where my accent colour is green, but this means that the shadow colour for flyouts coming from accented controls is green, and it doesn't look great.

If I have some xaml like this:

<Button Classes="theme-subtle accent">
    <TextBlock Text="Click Me">
    
    <Button.Flyout>
	<Flyout FlyoutPresenterClasses="theme-solid" >
            <!-- How do I make this flyout not use the accent class, but the default one? -->
        </Flyout>
    </Button.Flyout>
</Button>

How do I make the button flyout not inherit the accent class, but just show as a non-accented control?

[Modified 5 days ago]

Comments (4)

Posted 4 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Ben,

I pasted the code above in our sample project and added some content in the flyout but didn't see what you were referring to.  Can you give a full XAML sample that shows it that we can put in our sample project to see exactly what you mean?

Also I don't believe "theme-solid" is a built-in option in our themes for FlyoutPresenter.  Perhaps it's something you added custom support for?


Actipro Software Support

Posted 4 days ago by Ben Evans - Mr, Viper Applied Science
Avatar

Hi There,

Apologies yes, the above XAML was poor! Here is an edited version of the Avalonia default application, that shows the issue:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:ActiproAccentTest.ViewModels"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="ActiproAccentTest.Views.MainWindow"
        x:DataType="vm:MainWindowViewModel"
        xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
        Icon="/Assets/avalonia-logo.ico"
        Title="ActiproAccentTest">

    <Design.DataContext>
        <!-- This only sets the DataContext for the previewer in an IDE,
             to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
        <vm:MainWindowViewModel/>
    </Design.DataContext>

    <Button Classes="theme-subtle accent" HorizontalAlignment="Center" VerticalAlignment="Center">
        <TextBlock Text="My Text"/>
    
        <Button.Flyout>
	        <Flyout>
                <TextBlock Text="My Flyout Text" Padding="10"/>
            </Flyout>
        </Button.Flyout>
    </Button>
</Window>

I'm afraid I can't seem to upload images here, but interestingly the flyout shadow looks perfectly normal on Light theme. However, in dark theme I do get the accent-coloured shadow on Dark theme (by default, blue). In fact, I notice that this seems to be because the default shadow colour of the ShadowChrome control has changed. Is this the intended behaviour? If so, I suppose the solution would be to override the default ShadowChrome style?

[Modified 4 days ago]

Answer - Posted 3 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hi Ben,

Thank you for the clarification. Yes, dark themes may use the accent color tint because otherwise a default black shadow would barely show up. Adding a little color from the theme ensures it's somewhat visible, even if it's just subtle.

The color used comes from the ShadowColor resource that is generated.  You can follow the instructions in this documentation topic on creating a customized ThemeGenerator.  In your case, you'd want to override the ThemeGenerator.GetColorResource method and look for resourceKind == ThemeResourceKind.ShadowColor.  Then return whichever Color value you want to use instead of our default.  And follow the other steps in that documentation topic for installing your customized theme generator.  That will give you full control over the color that is used.


Actipro Software Support

Posted 3 days ago by Ben Evans - Mr, Viper Applied Science
Avatar

Thank you very much!

Add Comment

Please log in to a validated account to post comments.