How to group Path objects?
I am creating some 'map application' 开发者_StackOverflowin WPF, using C#. I use Visual Blend 2 to draw boundaries of countries, so as a result I got Path objects (written in XAML). Path is an object where the first point == last point, so path is always closed. Some countries (like Japan) has some islands, so as a result one country has more than 1 path.
I am trying to add some behaviors to those objects (countries - so 1 or more paths), like when user mouse is enter some country (or IsMouseOver property is 'true' - but it doesn't matter here), country is changing their background color.
Where some country == 1 path, there is no problem. But what can I do where there are more than 1 path to some countries?
So my question is: how to group paths in one object?
I was trying to use GeometryGroup class but I can't use it properly...
Do you have some ideas?
Your path can have more than one 'M' no problem and it works fine with path.Fill. Ultimately it depends on a type of figure you're drawing.
Here's a sample:
<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 code.
Create a plain C# class to use as a logical model for a country. Then it could contain a List<Path> CountryBoundaries
instance-variable, which it would manage the background colors for.
Then you need to hook-up mouseover-events of the paths to the correct country.
精彩评论