Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.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# 从树中删除UIElement UI并不能完全删除它_C#_Wpf - Fatal编程技术网

C# 从树中删除UIElement UI并不能完全删除它

C# 从树中删除UIElement UI并不能完全删除它,c#,wpf,C#,Wpf,我有一个WPF自定义控件,它允许我添加/删除一些UIElements路径对象 当添加每个元素时,我将其命名为一个名称,如28 29 1,28 29 2_28_29_3使用此代码 ContadorSimbolos += 1; string Nombre = string.Format("_{0}_{1}_{2}", this.Name, simbolo.Id, ContadorSimbolos.ToString().Trim()); Path MyPath = SimbolTools.TextTo

我有一个WPF自定义控件,它允许我添加/删除一些UIElements路径对象

当添加每个元素时,我将其命名为一个名称,如28 29 1,28 29 2_28_29_3使用此代码

ContadorSimbolos += 1;
string Nombre = string.Format("_{0}_{1}_{2}", this.Name, simbolo.Id, ContadorSimbolos.ToString().Trim());
Path MyPath = SimbolTools.TextToPath(simbolo.Path, Nombre);
PanelInferior1Contenedor.Children.Add(MyPath);
this.RegisterName(Nombre, MyPath);
在此之前,一切正常,但现在如果我删除前一阶段创建的对象之一,它将执行视觉删除

PanelInferior2Contenedor.Children.Remove(MyPath);
但是如果我使用

nombre = string.Format("_{0}_{1}_{2}", this.Name, IdSimbolo, i);
PathEncontrado = this.FindName(nombre) as Path;
要按名称查找该元素,它仍然可以找到它


我该怎么做才能完全移除它

强烈建议您使用和适当的,而不是在WPF的过程代码中创建和操作UI元素。您当前的方法有许多缺点:它太麻烦,需要太多的代码才能完成更少的工作。由于可视化树的复杂性,它容易出现各种微妙的问题,并且在多线程场景中不可行。@HighCore Tks为您提供帮助,我将查看ÍtemsControl实际上这是一个允许数据绑定的自定义控件。