martinj
Topic Author
Posts: 19
Joined: 20 Mar 2012, 15:38

How to create a custom shape?

10 Sep 2014, 14:49

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

Re: How to create a custom shape?

11 Sep 2014, 11:05

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!
 
martinj
Topic Author
Posts: 19
Joined: 20 Mar 2012, 15:38

Re: How to create a custom shape?

11 Sep 2014, 13:53

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

Re: How to create a custom shape?

15 Sep 2014, 19:45

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

Re: How to create a custom shape?

16 Sep 2014, 16:30

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);
 
martinj
Topic Author
Posts: 19
Joined: 20 Mar 2012, 15:38

Re: How to create a custom shape?

19 Sep 2014, 07:52

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 :)

Who is online

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