Gwynneth
Topic Author
Posts: 15
Joined: 20 Apr 2017, 18:31

Custom Decorator

29 May 2018, 15:08

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?
 
User avatar
sfernandez
Site Admin
Posts: 1911
Joined: 22 Dec 2011, 19:20

Re: Custom Decorator

30 May 2018, 20:31

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:
void UpdateGeometry(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
  using (StreamGeometryContext geo = this.Shape.Open())
  {
    // generate new geometry
  }
}

Who is online

Users browsing this forum: No registered users and 0 guests