【问题标题】:Programmatically creating a clickable area on an image以编程方式在图像上创建可点击区域
【发布时间】:2010-03-28 13:25:56
【问题描述】:

我正在尝试使用代码隐藏在 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();
        ?????
    }

我也不确定如何在我的图像中添加/删除此按钮,但我正在调查。

感谢任何帮助。

【问题讨论】:

    标签: wpf code-behind imagemap


    【解决方案1】:

    看到这个article by Rob Relyea here,我相信它回答了你的问题。

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

    考虑您可以将按钮不透明度设置为 0 以使其不可见。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-08-18
      • 2020-10-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-05
      相关资源
      最近更新 更多