Applying Actipro themes to a custom templated control

Themes, Shared, and Core Libraries for Avalonia Forum

Posted 4 days ago by Matt
Version: 25.2.1
Avatar

Hi,

I am still quite new to Avalonia in general so my understanding in this area is a little limited - go easy on me please :)

I am currently using modern theme throughout my application which is working well for native controls.

I have created a new templated control, a range slider, which is designed to look and feel like the native slider. It is quite simple - just a slider with two thumbs which can be used to define a value range, and an extra grabable area in between the thumbs that let the start/end range thumbs be moved together.

For styling, I have copied relevant snippets from the Avalonia slider control template and when the actipro theme is not applied my range slider does indeed look more or less identical to an existing slider with 2x thumbs. I can (kind of) replicate the Actipro slider by using modern theme colour resources explicitly throughout my template but this seems like a bit of a bodge. 

Question:

It seems clear that Actipro modern theme is replacing the entire control template the for slider, and I would like to copy the parts that apply to slider so that I can use them in my range control and have that update as I control the app theme globally. I have not been able to find the axaml for this control theme so I guess my question boils down to: are the modern control tempaltes available in axaml so that I can see what I need to use in my new control? In WPF getting the control template for a control was trivial and could be done within VS. Am I missing an equivalent for Avalonia?

thanks!

Matt

[Modified 4 days ago]

Comments (6)

Posted 4 days ago by Alves Nunes Samuel
Avatar

Hi,

I have exactly the same question, but for a simple Button.

I would like to override the Button to create a custom button, and I am using modern theme.

If I use the basic snippet from the avalonia stock Button control, and overrides it, it completely break all things.

The question is then, how can we get the "basic" controls and overrides them as we could do for the basic avalonia controls.

Thanks

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

Two different questions here, so I'll start with Matt's.

Matt, you might be happy to know that we've actually be working on a RangeSlider control as part of our Fundamentals product that will be released with v26.1.  Let us know if you'd like to test a preview build of that control once we get closer to release.

All Pro license customers have full access to our templates.  So while I'm not aware of an Avalonia way to easily pull a control template like you mentioned for WPF, you can download the full source of all our default styles and templates from the blue Actions button's menu on your organization account page. You can find the SliderThumb template at "\Source\Shared\Themes\Native\Slider.axaml".

If you don't want to redefine the template, you can also just apply the default template to your own Thumb implementation using our ControlTheme markup extension:

xmlns:actipro="http://schemas.actiprosoftware.com/avaloniaui"
...
<Thumb ... Theme="{actipro:ControlTheme SliderThumb}" />

More details on that extension can be found here.

Next...

Alves, your situation is a little different.  If you have your own theme for a derived class, you'll want to make sure your theme is "BasedOn" our theme to inherit all the default styles.  You can find more information on that here.


Actipro Software Support

Posted 3 days ago by Matt
Avatar

Thanks for the prompt response as always!

I have tried to apply your ControlTheme approach but without success - I am almost certainly doing it wrong. Would it be possible for a slightly more complete example please? I tried simply replacing my existing Thumb components within my template with the below but my thumbs turned into small orange circles.. is there another part I am missing?

thanks again!

<Thumb ... Theme="{actipro:ControlTheme SliderThumb}" />
Answer - Posted 3 days ago by Actipro Software Support - Cleveland, OH, USA
Avatar

The SliderThumb theme gets you the basics of the control template, but there are some additional properties set by our Slider native theme to complete the look.  I tried pasting the following into our Sample Browser and it matched the base appearance of our outling theme:

<Thumb Classes="horizontal" Theme="{actipro:ControlTheme SliderThumb}"
  BorderThickness="{actipro:ThemeResource SwitchBorderThickness}"
  Background="{actipro:ThemeResource SwitchBackgroundBrushOutline}"
  BorderBrush="{actipro:ThemeResource SwitchBorderBrushOutline}"
  Foreground="{actipro:ThemeResource SwitchForegroundBrushOutline}"
  />

If you look at the source for the Slider control template, you'll see there are also some styles that change the brushes for various events like pressed or disabled that you might want to copy into your solution as well.


Actipro Software Support

Posted 2 days ago by Matt
Avatar

Thasnk again! I have it working (after a fashion) but am also very much looking forward to your own implementation of a range slider (a very useful control) and yes, would be very keen to see early releases if possible - let me know how.

thanks,

Matt

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

Glad you got it working.  I've added a note about your interest in previewing the RangeSlider, and we can reach out closer to availability.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.