wpf WPF从网格中删除行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20860193/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
WPF Delete Row from grid
提问by gatordude
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
我对 WPF 很陌生,正在使用 WPF 构建图表应用程序。我正在动态添加新行,并且效果很好。删除行时出现问题。这是我添加行的代码
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.
谢谢。
回答by yo chauhan
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
嗨,我认为您的代码正确删除了 RowDefinition,但我认为错误的是您还需要删除该行中的 Grid 子项,例如
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.
如果您不删除孩子,则 RowDefinition 将被删除,但孩子将被转移到另一行。我希望这会给您一个想法。

