Confusion about using OverrideMetadata when subclassing Noesis::Slider (example included)
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:
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.
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
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:
Code: Select all
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>())
);
}
};
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.
Code: Select all
<custom:FSlider x:Name="MyFSlider" Minimum="0" Maximum="5" Value="3" Width="100" Height="20"/>
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)
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.Goal for my test is to add a custom red background to the slider
Re: Confusion about using OverrideMetadata when subclassing Noesis::Slider (example included)
Hi,
the main goal is to add custom control logic, while also allowing optional customization of the visual appearance.
Kind Regards,
Miroslav
the main goal is to add custom control logic, while also allowing optional customization of the visual appearance.
Kind Regards,
Miroslav
-
-
sfernandez
Site Admin
- Posts: 3363
- Joined:
Re: Confusion about using OverrideMetadata when subclassing Noesis::Slider (example included)
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:
Can you try that?
If you don't do that, you just need to define an implicit style for your custom slider in your application resources:
Code: Select all
NS_IMPLEMENT_INLINE_REFLECTION(FSlider, Noesis::Slider, "Tests.FSlider") // define a namespace that can be used later in XAML
Code: Select all
<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>
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 2 guests