Page 1 of 1

How to create a custom shape?

Posted: 10 Sep 2014, 14:49
by martinj
I'm trying to convert one of the examples from the book "WPF control development unleashed" to Noesis.

In this example they create a simple arc class that inherits from "Shape" and the references that in the XAML.
But I cannot figure out how to achieve this in Noesis - there is no "DefiningGeometry" property to override in the Shape class. Is this the wrong way to do it in Noesis?

I've attached a package containing my sample code.

Another problem that I guess is possible, but inconvenient, to work around is that multibinding/multiconverters are not supported in Noesis. Is this something that you plan to support?

Example code:
https://dl.dropboxusercontent.com/u/244 ... itypackage

Re: How to create a custom shape?

Posted: 11 Sep 2014, 11:05
by jsantos
Hi!

While shapes are very powerful, you must always be aware that they do come with a high memory footprint. When you look at the inheritance chain of Ellipse and contrast that to the Button, they have much of the same infrastructure. Thus, if you were building some sort of application which needed to plot out 1000s of points of data, and you draw these plot points using the Ellipse, it would be just about as much overhead as drawing 1000 Buttons on the window (more or less).

When you need to generate large amounts of graphical data which does not require any user interactivity, we recommend using a StreamGeometry by filling the Data property of a Path as explained here.

I downloaded your package but it seems to be corrupted because I am unable to import it to a project.

Regarding, multibinding/multiconverters, yes, they are in the roadmap, low-priority right now (this is one of features that Microsoft deprecated from WPF to Windows Phone). If you need this, please file a bug to track this feature.

Thanks!

Re: How to create a custom shape?

Posted: 11 Sep 2014, 13:53
by martinj
I've created a new package that is available from this link (though the old package does work when I download it myself :/)
https://dl.dropboxusercontent.com/u/244 ... itypackage

In this case there would only be one instance of the created shape (it would be animated though). But anyway, I can't figure out how to define the geometry for the shape so that Noesis uses it.

I guess the Path alternative would be viable in this case. A "complete" example (a small sample class) would be helpful to understand how this would be implemented. Should I override GetData(), or define my own "Data" dependency property?

Re: How to create a custom shape?

Posted: 15 Sep 2014, 19:45
by jsantos
Hi, the package is working now. I don't know why but the import process fails if I click in the package itself. I have to import it from Unity. Anyway...

The problem you have is that we do not support extending Shapes right now:
public class Arc : Noesis.Shape
Let me analyze your sample and find a solution.

Re: How to create a custom shape?

Posted: 16 Sep 2014, 16:30
by jsantos
For now, until Extending Shapes in C# is implemented, you can achieve the same result by using a Path instead of your Damalini:Arc.
<ControlTemplate TargetType="ProgressBar">
    <Grid>
        <Ellipse Stroke="Black" Fill="{TemplateBinding Background}" />
        <Ellipse Stroke="Black" Margin="40" Fill="White" />
        <Path x:Name="arc" />
    </Grid>
</ControlTemplate>
And the each time the ProgressBar value changes you do:
Path arc = _progress.GetTemplateChild("arc").As<Path>();

StreamGeometry geom = new StreamGeometry();
using (StreamGeometryContext context = geom.Open())
{
    context.BeginFigure(startPoint, false);
    context.ArcTo(endPoint, arcSize, 0, isLargeArc, false);
}

arc.SetData(geom);

Re: How to create a custom shape?

Posted: 19 Sep 2014, 07:52
by martinj
Thanks!

It works properly now. It would be nice, at some point in the future, to be able to extend Shape (or perhaps Path) to encapsulate specialized geometry. But this works just fine for now :)