Carri
Carri

Reputation: 193

WPF: Drawing Geometries from a List<Geometry>

I'm trying to learn wpf and in the process I'm basically trying to load a series of paths and draw them. I have several test "files" that contain certain samples of different geometry types. The "files" each have a different number of shapes.

What is the best way to load these files into a WPF application. I obviously don't want to create individual paths in the XAML and so there is a better way, I just don't know it. I'd still like the shapes to be hit-testable for example. I don't want to just do a union and convert the multiple shapes to a single set of shapes.

I'm doing this in C# 4.0.

EDIT: I've basically just serialized the coordinates of various polygons to text files. I then create Paths from these text files. If I have a list containing 3 polygons, how do I render them without explicitly creating 3 paths in the XAML file?

Upvotes: 4

Views: 1035

Answers (3)

DefenestrationDay
DefenestrationDay

Reputation: 3852

If you're talking Shapefiles, then Mapsui would be one good option.
I prefer not re-inventing the wheel all the time..

Upvotes: 1

Shimmy Weitzhandler
Shimmy Weitzhandler

Reputation: 104821

I think you should use the XamlReader class, then once you have concrete objects you can easily add them wherever parent control you wish.

Use XamlReader.Load if you want to load it via a stream (e.g. FileStream), or XamlReader.Parse if they are in available strings.

These methods will return the root of the constructed object tree (which might even be a Path as well).

Upvotes: 0

Muad'Dib
Muad'Dib

Reputation: 29266

you should read them in (say from a file) and use the XamlReader to create concrete instances of them. you can store them in an ObservableCollection, and then bind said collection to an ItemsControl where you have specified the panel as a Canvas.

Upvotes: 0

Related Questions