Custom Decorator
Hi, I'm trying to create a custom Decorator control for a Unity project. In WPf this means inheriting from Decorator and overriding OnRender(). However, in NoesisGUI I cannot override the OnRender method. Furthermore, since the Decorator control does not allow a ControlTemplate I cannot style it.
My current solution is to inherit from ContentControl, add a 'Shape' dependency property of type StreamGeometry that is created when certain properties change. The control's view then contains a Path that has its Data property data bound to the 'Shape' dependency property. Although this works it feels rather 'hacky' and I'd say technically incorrect. That is, each dependency property now has a PropertyChangedCallback defined that handles the creating of the StreamGeometry (basically rendering) which I'd say is what FrameworkPropertyMetadataOptions.AffectsRender is for.
So, the question is if there is a different/ better way to do custom rendering for a control?
My current solution is to inherit from ContentControl, add a 'Shape' dependency property of type StreamGeometry that is created when certain properties change. The control's view then contains a Path that has its Data property data bound to the 'Shape' dependency property. Although this works it feels rather 'hacky' and I'd say technically incorrect. That is, each dependency property now has a PropertyChangedCallback defined that handles the creating of the StreamGeometry (basically rendering) which I'd say is what FrameworkPropertyMetadataOptions.AffectsRender is for.
So, the question is if there is a different/ better way to do custom rendering for a control?
-
sfernandez
Site Admin
- Posts: 3154
- Joined:
Re: Custom Decorator
Unfortunately there is no support for custom render controls in C# Noesis (it is only available in C++ API).
The solution you chose is the only one available right now.
But you should be able to create the StreamGeometry once and reuse it when your control properties change:
The solution you chose is the only one available right now.
But you should be able to create the StreamGeometry once and reuse it when your control properties change:
Code: Select all
void UpdateGeometry(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
using (StreamGeometryContext geo = this.Shape.Open())
{
// generate new geometry
}
}
Who is online
Users browsing this forum: maherne and 2 guests