2
我想清楚了電網的孩子例如所有的值,如果我的網格的一個孩子是文本我想從文本沒有重置或清除它來回網名?怎麼樣?不明確的電網,但在文本框中我想清楚了在網格中的所有值沒有(數據網格)的孩子在WPF
我想清楚了電網的孩子例如所有的值,如果我的網格的一個孩子是文本我想從文本沒有重置或清除它來回網名?怎麼樣?不明確的電網,但在文本框中我想清楚了在網格中的所有值沒有(數據網格)的孩子在WPF
下一頁功能將在指定的對象指定類型的所有控件搜索:
/// <summary>
/// Helper function for searching all controls of the specified type.
/// </summary>
/// <typeparam name="T">Type of control.</typeparam>
/// <param name="depObj">Where to look for controls.</param>
/// <returns>Enumerable list of controls.</returns>
public static IEnumerable<T> FindVisualChildren<T>(DependencyObject depObj)
where T : DependencyObject
{
if (depObj != null)
{
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject child = VisualTreeHelper.GetChild(depObj, i);
if (child != null && child is T)
{
yield return (T)child;
}
foreach (T childOfChild in FindVisualChildren<T>(child))
{
yield return childOfChild;
}
}
}
}
由於這項功能的作者......不記得在那裏我把它。現在
可以爲所有的文本框例子清晰的價值觀:
foreach (TextBox child in FindVisualChildren<TextBox>(yourGrid))
{
child.Text = string.Empty;
}
清除文本下面的代碼應該清除所有文本框:
var textboxes = grid.Children.OfType<TextBox>();
foreach (var textBox in textboxes)
textBox.Text = String.Empty;
我修改的問題,瞭解我想 – kartal 2011-03-29 14:35:40
編輯我的答案是什麼。 – 2011-03-29 14:42:11
簡短而親切。 – Nitin 2012-11-01 17:16:47