以编程方式在图像上创建可点击区域
我正在尝试使用代码隐藏在 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();
?????
}
我也不确定如何在我的图像中添加/删除此按钮,但我正在寻找进入那个。
任何帮助表示赞赏。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请参阅Rob Relyea 的文章,我相信它有答案你的问题。
考虑您可以将按钮不透明度设置为 0 以使其不可见。
See this article by Rob Relyea here, I believe it answers your question.
Consider you could set the button opacity to 0 to make it invisible.