开发者

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?


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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜