开发者

Clearing text boxes inside of a Control

开发者 https://www.devze.com 2023-03-26 11:31 出处:网络
I have a series of of tabs that hold text boxes in them.Some of the tabs have a control that contains Text Boxes inside of a Scrollview as well.I am trying to iterate through the tabs and clear the co

I have a series of of tabs that hold text boxes in them. Some of the tabs have a control that contains Text Boxes inside of a Scrollview as well. I am trying to iterate through the tabs and clear the content of the text boxes.

I was going to use this:

foreach(TabItem item in Tabs.Items)
{
    ClearTextBoxes(this);
}

I then use this to clear to the text boxes:

TextBox tb = obj as TextBox;
if (tb != null)
tb.Text = "";
for (int i = 0; i &l开发者_JAVA技巧t; VisualTreeHelper.GetChildrenCount(obj); i++)
{
    ClearTextBoxes(VisualTreeHelper.GetChild(obj, i));
}

It is currently only clearing the first tab and none of the rest.

Any ideas?


Use the LogicalTreeHelper. Only the items of the currently active tab are contained in the visual tree, therefore the visual tree helper is not the best choice for your task.

Iterating over the tab items is IMO not necessary, only if you have a lot of other controls not residing in the tab-items and therefore want to spare cpu power. As already mentioned by Bela R, there is an error in your call to ClearTextBoxes().


I think it should be ClearTextBoxes(item) and not ClearTextBoxes(this)

foreach(TabItem item in Tabs.Items)
{
    ClearTextBoxes(item);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消