Page 1 of 1

Confusion about using OverrideMetadata when subclassing Noesis::Slider (example included)

Posted: 23 Nov 2025, 21:12
by hehe
Hi,

I’m trying to create a custom slider by subclassing Noesis::Slider, but I’m running into confusion about how OverrideMetadata is supposed to be used in Noesis.
Goal for my test is to add a custom red background to the slider, but keep all other visual behavior and style from the default Noesis Slider.

Here is my current custom slider:
class FSlider : public Noesis::Slider
{
public:
    FSlider();
    void OnValueChanged(float oldValue, float newValue) override;
    void OnRender(Noesis::DrawingContext* drawingContext) override;
    void SetColor(const Noesis::Color& newColor)

private:
    Noesis::Color CurrentColor;
    
    NS_IMPLEMENT_INLINE_REFLECTION(FSlider, Noesis::Slider)
    {
        auto* data = NsMeta<Noesis::DependencyData>(Noesis::TypeOf<SelfClass>());
        
        // ---------- This is the part I’m confused about: -----------//
        data->OverrideMetadata<Noesis::Slider>(
            Noesis::Control::DefaultStyleKeyProperty,
            "DefaultStyleKey",
            Noesis::FrameworkPropertyMetadata::Create(Noesis::TypeOf<Noesis::Slider>())
        );
    }
};
Note
Fslider works fine if instantiated in code.
Once I define Fslider in xaml and add reflection part, I see only background without track and thumb.
<custom:FSlider x:Name="MyFSlider" Minimum="0" Maximum="5" Value="3" Width="100" Height="20"/>
My question:
What should be the correct metadata override for DefaultStyleKeyProperty?
Is there any minimal working example showing how to extend a core Noesis control and override its metadata correctly?

Thanks.
Kind Regards,
Miroslav

Re: Confusion about using OverrideMetadata when subclassing Noesis::Slider (example included)

Posted: 25 Nov 2025, 18:12
by jsantos
Goal for my test is to add a custom red background to the slider
Have you considered creating a template for this instead of adding a new class? Subclassing is always a heavy decision and can be difficult to maintain. I wanted to ask before going into more detail.

Re: Confusion about using OverrideMetadata when subclassing Noesis::Slider (example included)

Posted: 27 Nov 2025, 11:51
by hehe
Hi,

the main goal is to add custom control logic, while also allowing optional customization of the visual appearance.

Kind Regards,
Miroslav

Re: Confusion about using OverrideMetadata when subclassing Noesis::Slider (example included)

Posted: 01 Dec 2025, 12:29
by sfernandez
You only have to override the "DefaultStyleKey" if you want to provide your own default style and template for your custom control using the Noesis::GUI::RegisterDefaultStyles(uri) from IntegrationAPI.h.

If you don't do that, you just need to define an implicit style for your custom slider in your application resources:
NS_IMPLEMENT_INLINE_REFLECTION(FSlider, Noesis::Slider, "Tests.FSlider") // define a namespace that can be used later in XAML
<ResourceDictionary
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:Tests"> <!-- same namespace used in code -->
  ...
  <Style TargetType="{x:Type local:FSlider}">
    <Setter Property="Template" Value="{StaticResource YourFSliderTemplate}"/>
    ...
  </Style>
</ResourceDictionary>
Can you try that?