Last active
May 14, 2021 04:26
-
-
Save Mahno74/8b6a4457166a439c0eb998184ebef60e to your computer and use it in GitHub Desktop.
WPF Обход однотипных "контролов"
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//В 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