WPF从网格删除行 [英] WPF Delete Row from grid

查看:116
本文介绍了WPF从网格删除行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对WPF很新,并且正在使用WPF构建一个Charting应用程序。我正在动态添加新行,并且它完美地工作。删除行时出现问题。这是我添加行的代码

  RowDefinition newRow = new RowDefinition(); 
newRow.Name =ADX;
newRow.Height = new GridLength(1,GridUnitType.Star);
this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Add(newRow);
Grid.SetRow(scs,this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Count - 1);
this.techIndicatorToRowDefinitionMap [ADX] = newRow;

和删除行的代码是

  this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Remove(this.techIndicatorToRowDefinitionMap [ ADX]); 

当我删除这些行时,似乎随机行被删除。你能告诉我是否有更简单的方法来跟踪行并删除它们,或者是否存在此代码中的错误。



谢谢。

解决方案您好,我认为您的代码正确地移除了RowDefinition,但是我认为错误的是您还需要移除该行中Grid的子项,如

  this.chartForm.sciChartControl.ContentGrid.Children.Remove(scs); 
this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Remove(this.techIndicatorToRowDefinitionMap [ADX]);

如果您不移除子元素,RowDefinition将被移除,但子元素将被移至另一行。希望这会给你一个主意。


I am pretty new to WPF and am building an Charting application using WPF. I am adding new rows dynamically and it works perfectly. I am seeing a problem when removing rows. This is my code for adding rows

RowDefinition newRow = new RowDefinition();
newRow.Name = "ADX";
newRow.Height = new GridLength(1, GridUnitType.Star);
this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Add(newRow);
Grid.SetRow(scs, this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Count - 1);
this.techIndicatorToRowDefinitionMap["ADX"] = newRow;

and the code to remove the Row is

this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Remove(this.techIndicatorToRowDefinitionMap["ADX"]);

When I remove the rows , it seems like random rows are removed. Can you tell me if there is an easier way to keep track of rows and delete them or if there is a bug in this code .

Thanks.

解决方案

Hi I think your code is Removeing the RowDefinition correctly but what I think wrong is you also need to remove the children of Grid in that Row like

this.chartForm.sciChartControl.ContentGrid.Children.Remove(scs);
this.chartForm.sciChartControl.ContentGrid.RowDefinitions.Remove(this.techIndicatorToRowDefinitionMap["ADX"]);

If you wont remove the child the RowDefinition will be removed but child will be shifted to another row .I hope this will give you an idea.

这篇关于WPF从网格删除行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆