0

コードビハインドを使用して、wpf の画像に「イメージマップ」を作成しようとしています。

次の 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>

これを WPF アプリの特定の画像のボタンに変換しようとしています。

私はすでにこれの一部を行っていますが、ポリゴンをボタンの「テンプレート」として設定することに固執しています:

    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();
        ?????
    }

このボタンを画像に追加/画像から削除する方法もわかりませんが、調べています。

どんな助けでも大歓迎です。

4

1 に答える 1

0

こちらのRob Relyeaによるこの記事を参照してください。あなたの質問に答えていると思います。

 //Create a button from scratch
        Button perhapsButton = new Button();
        perhapsButton.Content = "Perhaps"
        perhapsButton.Click += new RoutedEventHandler(perhapsButton_Click);
        container.Children.Add(perhapsButton);

ボタンの不透明度を 0 に設定して非表示にできると考えてください。

于 2010-04-19T16:16:50.363 に答える