1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
namespace WpfComboBox
{
/// <summary>
/// Logique d'interaction pour MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void Grid_Loaded(object sender, RoutedEventArgs e)
{
string prefixName = "TxbM";
TextBox tb ;
tb = new TextBox();
tb.Name = prefixName + (104).ToString();
RegisterName(tb.Name, tb); //nota bene necessaire sinon recherche par nom echoue(FindName)
tb.Text = "TxbM" + (104).ToString();
tb.Foreground = Brushes.Brown ;
tb.Margin = new Thickness(5);
tb.IsEnabled = false;
tb.IsReadOnly = true;
pnl.Children.Add(tb);
}
private void btnModif_Click(object sender, RoutedEventArgs e)
{
string prefixName = "TxbM";
string tbName;
TextBox tb;
for (int i = 1; i < 5; i++)
{
tbName = prefixName + i.ToString();
tb = FindName(tbName) as TextBox;
if (tb != null)
{
tb.IsEnabled = true; // Avidement cette ligne ne fonctionne pas, comment faire
tb.IsReadOnly = false; // Avidement cette ligne ne fonctionne pas, comment faire
tb.Background= Brushes.Beige ;
}
}
tbName=prefixName+(104).ToString();
tb = FindName(tbName) as TextBox;
if (tb != null)
{
tb.IsEnabled = true;
tb.IsReadOnly = false;
tb.Background = Brushes.DarkBlue;
}
}
}
} |
Partager