WPF: drawing geometries from the <Geometry> list

I am trying to learn wpf, and in the process I am basically trying to load a number of paths and draw them. I have several test โ€œfilesโ€ that contain specific samples of different types of geometry. Each "file" has 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 separate paths in XAML, and therefore there is a better way, I just donโ€™t know this. I would still like forms to be tested, for example. I donโ€™t want to just merge and convert multiple shapes into one set of shapes.

I do this in C # 4.0.

EDIT: I just simply serialize the coordinates of the various polygons into text files. Then I create Paths from these text files. If I have a list containing 3 polygons, how can I visualize them without explicitly creating 3 paths in the XAML file?

+4
source share
3 answers

you must read them (say, from a file) and use XamlReader to create specific instances of them. you can save them in an ObservableCollection and then bind this collection to the ItemsControl where you specified the panel as Canvas .

0
source

If you say Shapefiles , then Mapsui would be one good option.
I prefer not to reinvent the wheel all the time ..

+1
source

I think you should use the XamlReader class, and then when you have specific objects, you can easily add them wherever you want to control the parent element.

Use XamlReader.Load if you want to load it through a stream (e.g. FileStream ) or XamlReader.Parse if they are in the available lines.

These methods will return the root of the tree of constructed objects (it could even be Path ).

0
source

All Articles