以编程方式在图像上创建可点击区域
问题描述:
我试图在使用代码隐藏的wpf中的图像上创建“imagemaps”。以编程方式在图像上创建可点击区域
请参阅下面的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();
?????
}
我对如何添加也不能确定/删除此按钮去/从我的形象,但我正在调查。
任何帮助表示赞赏。
答
看到这个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,使其不可见。
不知道了,如果这固定它,但我标记为答案无论如何.. – 2010-09-14 09:09:27