Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将唯一特性附着到wpf中的LineGeometry对象_C#_Wpf - Fatal编程技术网

C# 将唯一特性附着到wpf中的LineGeometry对象

C# 将唯一特性附着到wpf中的LineGeometry对象,c#,wpf,C#,Wpf,我们知道,当将属性附加到画布上绘制的形状时,形状对象的标记属性非常方便。另一方面,我们鼓励使用轻量级图形对象,例如:LineGeometry 如何将唯一属性附加到此类的实例 注: 我想在画布上添加1000多行,我还想能够识别哪个是哪个。因为这些线将代表钢筋等结构构件的各个部分。因此,我希望能够单击一条线并识别它所代表的钢筋。将线形几何体声明为,这意味着您无法直接扩展它。但是,没有什么可以阻止您使用LineGeometry类型的属性声明一个新类,并在其中声明您的新属性: public class

我们知道,当将属性附加到画布上绘制的形状时,形状对象的标记属性非常方便。另一方面,我们鼓励使用轻量级图形对象,例如:
LineGeometry

如何将唯一属性附加到此类的实例

注:
我想在画布上添加1000多行,我还想能够识别哪个是哪个。因为这些线将代表钢筋等结构构件的各个部分。因此,我希望能够单击一条线并识别它所代表的钢筋。

线形几何体声明为,这意味着您无法直接扩展它。但是,没有什么可以阻止您使用
LineGeometry
类型的属性声明一个新类,并在其中声明您的新属性:

public class ExtendedLineGeometry
{
    public object CustomProperty { get; set; }
    public LineGeometry LineGeometry { get; set; }
}
然后,无论您想在何处访问
LineGeometry
对象,您只需要像这样引用它:

Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = extendedLineGeometry.LineGeometry;
Path myPath = new Path();
myPath.Stroke = extendedLineGeometry.CustomProperty;
myPath.StrokeThickness = extendedLineGeometry.CustomProperty2;
myPath.Data = extendedLineGeometry.LineGeometry;
根据您在额外属性中添加的内容,您可以将其定义为一个
双精度
,甚至可以添加另一个属性并执行以下操作:

Path myPath = new Path();
myPath.Stroke = Brushes.Black;
myPath.StrokeThickness = 1;
myPath.Data = extendedLineGeometry.LineGeometry;
Path myPath = new Path();
myPath.Stroke = extendedLineGeometry.CustomProperty;
myPath.StrokeThickness = extendedLineGeometry.CustomProperty2;
myPath.Data = extendedLineGeometry.LineGeometry;

更新>>>

我想我只是解释了你会如何使用它。然而,你的评论让我相信你不明白。您的
GeometryGroup.Children
属性可以获取
LineGeometry
对象。您的
ExtendedLineGeometry
对象中有一个
LineGeometry
对象,因此您只需将其传递给
子对象
集合:

geometryGroup.Children.Add(extendedLineGeometry.LineGeometry);

但是,您可以创建,很可能您从一开始就采取了错误的方法。根据您正在处理的数据的性质或您想要关联的数据,UI可能不是该数据的正确位置。请发布一些关于您试图添加到这些UI元素中的属性的附加信息,以获得更好的答案。@HighCore我猜我也走错了路。我添加了一些注释。我真的很感激任何能让我走上正确方向的帮助。@HighCore三周后,现在我明白你的意思了!我有回来阅读我的旧帖子的习惯!我学到了很多!谢谢:)实际上我已经试过了,但是我怎么能把这些添加到GeometryGroup类中呢。它不接受这个扩展类。