0

I am new to WPF and came across a situation where i think adding controls dynamically would be good.

But i don't know if there is way to it dynamically using code. I want to add following using Code

<WrapPanel Height="39">
      <TextBox Width="93" Margin="-1,5,0,0"></TextBox>
      <TextBox Width="76" Margin="0,5,0,0"></TextBox>
      <TextBox Width="70" Margin="0,5,0,0"></TextBox>
      <TextBox Width="70" Margin="0,5,0,0"></TextBox>
      <TextBox Width="127" Margin="0,5,0,0"></TextBox>
      <TextBox Width="100" Margin="0,5,0,0"/>
</WrapPanel>

I tried THIS method,but it did not work

Community
  • 1
  • 1
Richa
  • 3,261
  • 2
  • 27
  • 51

1 Answers1

0

Try below code

 var panel = new WrapPanel() { Height = 39 };
            panel.Children.Add(new TextBox() { Width = 93, Margin = new Thickness(-1, 5, 0, 0) });
            panel.Children.Add(new TextBox() { Width = 76, Margin = new Thickness(0, 5, 0, 0) });
            panel.Children.Add(new TextBox() { Width = 70, Margin = new Thickness(0, 5, 0, 0) });
            panel.Children.Add(new TextBox() { Width = 70, Margin = new Thickness(0, 5, 0, 0) });
            panel.Children.Add(new TextBox() { Width = 127, Margin = new Thickness(0, 5, 0, 0) });
            panel.Children.Add(new TextBox() { Width = 100, Margin = new Thickness(0, 5, 0, 0) });
            this.Content = panel;
Vimal CK
  • 3,543
  • 1
  • 26
  • 47