如何删除网格行上以前更新的UIElement以添加新的UIElement? [英] How to remove previously updated UIElement on grid row to add new UIElement?
问题描述
我在silverlight工作,我有一个名为"bigGrid"的网格。它包含三行,在第一行我有组合框,我在两个不同的行上更新两个UI元素加载comboBox(我的意思是第二行bigGrid(因为bigGrid
是所有的父级)或第一和第二行我的代码中的rowGrid)。
I am working in silverlight where i have a grid called "bigGrid" which contains three rows and on the first row i have combobox and i update two UI elemnt on two different rows on Loading the comboBox (i mean second row bigGrid(because bigGrid is parent of all) or first and second row of rowGrid in my code).
现在在selectionChanged组合框的事件我必须用从组合框中选择的UI元素替换以前渲染的UI元素(如果UI元素是一个它将被显示在一行上,如果UI元素是两个,它们将一个接一个地显示在两个
不同的行上(请注意,在加载此组合框时,我会连续两行显示2个UI元素。)
Now on selectionChanged Event of combobox i have to replace the previously rendered UI elemnts with the UI element selected from combo box (If the UIelement is one it will be displayed on one row and if the UI elements are two they will be displayed on two different rows one after other (Please note that on Loading this combobox i display 2 UI elemnts in 2 consecutive rows.)
现在出现问题?:当我加载组合框时,问题在两行中有两个UIelement初始化。但是当我渲染2个元素时,它在Selectionchnaged事件上然后它被罚款为2个UIElements (它取代了之前两行上
Loaded事件的呈现。但问题是我只显示了1个UIE第一行中的lement 因为选择更改事件中的最近渲染的uiElement无疑在第一行更新但第二行的UI元素(来自组合框
已加载甚至仍然存在)。
Now Problem ?: The problem in when i load combobox the grids are intialised with two UIelement on 2 rows. but on Selectionchnaged event when i render 2 uielements then it wroks fine for 2 UIElements (it replaces the previous rendering of Loaded event on both rows . But the problem is when i dispaly only 1 UIElement in first row because MY RECENTLY RENDERED uiElement on selection changed event is no doubt updated in first row but the UI element of second row (from combobox Loaded even still persists).
如何删除这个以前持久存在的UI元素?
我的代码(请注意我只提供了有用的代码。 Ofcourse combe在某个地方声明,它也有项目。
My code for (please note that i have given just useful code. Ofcourse combe is declared somewhere and it has Items as well)
public Grid somefunction() //this function returs the final bigGrid (which contains all the ROWS CONATINING ui ELEMNTS)
{
cmb.Loaded += (o3, e) =>
{
foreach (object o in pv.Root.Parameter)
{
param = (Parameter)o;
if (o is Parameter)
{
rowGrid = IntializeUIElements(param, atrbt);
}
Grid.SetRow(rowGrid, loopCount);
}
bigGrid.Children.Add(rowGrid);
loopCount++;
};
cmb.SelectionChanged += (o1, e) =>
{
string selectedComboItem = cmb.SelectedItem.ToString();
Grid storeRowGrid = new Grid();
for (int i = 0; i < pv.Root.Parameter.Count; i++)
{
storeRowGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto });
}
int count = 0;
foreach (object o in pv.Root.Parameter)
{
if (o is Parameter)
{
rowGrid = IntializeUIElements(param, atrbt); //It returns the grid with UI element
Grid.SetRow(rowGrid, count);
storeRowGrid.Children.Add(rowGrid);
Grid.SetRow(storeRowGrid, count);
if (bigGrid.Children.Count > 1)
{
bigGrid.Children.RemoveAt(bigGrid.Children.Count - 1); //this is to remocve previous item on selection change
}
count++;
}
}
bigGrid.Children.Add(storeRowGrid);
};
Grid.SetColumn(cmb, 1);
comboRowGrid.Children.Add(cmb);
Grid.SetRow(comboRowGrid, 0);
bigGrid.Children.Add(comboRowGrid); //This BigGrid is parent Grid.
return bigGrid;
}
|