Skip to content

Instantly share code, notes, and snippets.

@Mahno74
Last active May 14, 2021 04:26
Show Gist options
  • Save Mahno74/8b6a4457166a439c0eb998184ebef60e to your computer and use it in GitHub Desktop.
Save Mahno74/8b6a4457166a439c0eb998184ebef60e to your computer and use it in GitHub Desktop.
WPF Обход однотипных "контролов"
//В WPF обход всех RadioButton в StackPanel radioStack
foreach (UIElement c in radioStack.Children) {
if (c is RadioButton)
((RadioButton)c).IsChecked = false;
}
//Пример обхода всех TextBox-ов
foreach (Control control in Controls)
{
TextBox tb = control as TextBox;
if (tb != null)
{
tb.Text = "Text";
}
}
// Альтернативный вариант (.NET 3.5 и выше):
// Пример обхода всех TextBox-ов
// Вместо TextBox можно подставить другой элемент управления
foreach (var tb in Controls.OfType<TextBox>())
{
tb.Text = "Text";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment