hehe
Topic Author
Posts: 6
Joined: 11 Apr 2025, 10:16

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

23 Nov 2025, 21:12

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
 
User avatar
jsantos
Site Admin
Posts: 4823
Joined: 20 Jan 2012, 17:18
Contact:

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

25 Nov 2025, 18:12

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.
 
hehe
Topic Author
Posts: 6
Joined: 11 Apr 2025, 10:16

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

27 Nov 2025, 11:51

Hi,

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

Kind Regards,
Miroslav
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

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

01 Dec 2025, 12:29

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?

Who is online

Users browsing this forum: Bing [Bot], Semrush [Bot] and 2 guests