Dynamically creating an ImageMap (clickable area on image) in WPF using codebehind.

Posted by Thomas Stock on Stack Overflow See other posts from Stack Overflow or by Thomas Stock
Published on 2010-03-28T13:25:56Z Indexed on 2010/03/28 13:33 UTC
Read the original article Hit count: 1383

Filed under:
|
|

Hi, I'm trying to create "imagemaps" on an image in wpf using codebehind.

See the following XML:

<Button Type="Area">
  <Point X="100" Y="100"></Point>
  <Point X="100" Y="200"></Point>
  <Point X="200" Y="200"></Point>
  <Point X="200" Y="100"></Point>
  <Point X="150" Y="150"></Point>
</Button>

I'm trying to translate this to a button on a certain image in my WPF app.

I've already did a part of this, but I'm stuck at setting the Polygon as the button's "template":

    private Button GetAreaButton(XElement buttonNode)
    {
        // get points
        PointCollection buttonPointCollection = new PointCollection();

        foreach (var pointNode in buttonNode.Elements("Point"))
        {
            buttonPointCollection.Add(new Point((int)pointNode.Attribute("X"), (int)pointNode.Attribute("Y")));
        }

        // create polygon
        Polygon myPolygon = new Polygon();
        myPolygon.Points = buttonPointCollection;
        myPolygon.Stroke = Brushes.Yellow;
        myPolygon.StrokeThickness = 2;

        // create button based on polygon
        Button button = new Button();
        ?????
    }

I'm also unsure on how to add/remove this button to/from my image, but I'm looking into that.

Any help is appreciated.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about imagemap