How to group Path objects?

I am creating some “map application” in WPF using C #. I use Visual Blend 2 to draw the borders of countries, so as a result I got Path objects (written in XAML). A path is an object where the first point == the last point, so the path is always closed. Some countries (for example, Japan) have some islands, therefore, as a result, one country has more than 1 path.

I am trying to add some types of behavior to these objects (countries are one or several paths), for example, when a user mouse enters a country (or the IsMouseOver property is “true”), but it doesn’t matter here), the country changes the background color .

If in some country == 1 way, there are no problems. But what can I do if in some countries there is more than one way?

So my question is: how to group paths in one object?

I tried to use the GeometryGroup class, but I cannot use it correctly ...

Do you have any ideas?

+3
source share
2 answers

There may be more than one "M" in your path, no problem, and it works great with path.Fill. Ultimately, it depends on the type of drawing you are drawing.

Here is an example:

<Path Data="M10,10 h100 v100 h-100z M30,30 h50 v50 h-50z" 
     Stroke="Gray" 
     StrokeThickness="1" 
     Fill="Blue"/>

or Geometry.Parse("M10,10 h100 v100 h-100z M30,30 h50 v50 h-50z")if you use the code.

+4
source

Create a simple C # class to use as a logical model for a country. It can then contain an instance variable List<Path> CountryBoundariesthat will control the background colors for.

Then you need to connect the path mouse events to the correct country.

+1
source

Source: https://habr.com/ru/post/1795732/


All Articles