title: How to create a Button from code in WPF and Python?
body: <p>I need to build multiple buttons, but I can't display any button! this is my code of a WPF application with IronPython 2.7..</p>
  
  <p>I've tried this in two different ways, with "Grid.Children.Add(button)" and without that but anything displays..</p>
  
  <p>XAML:</p>
  
  <pre><code>&lt;Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:Forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" 
          x:Name="NewWindow" Height="564.22" Width="993.2"&gt;
  
      &lt;Grid x:Name="grid" Margin="0,0,75.2,92.4"&gt;
          &lt;Grid.ColumnDefinitions&gt;
              &lt;ColumnDefinition/&gt;
          &lt;/Grid.ColumnDefinitions&gt;  
          &lt;Button Content="Create a Button from code" HorizontalAlignment="Left"
           Margin="712,418,0,0" VerticalAlignment="Top" Width="167" Height="61"
           Click="CreateButtons_Click"/&gt;     
      &lt;/Grid&gt;
  &lt;/Window&gt;
  </code></pre>
  
  <p>CODE:</p>
  
  <pre><code>import clr
  clr.AddReferenceToFileAndPath("IronPython.Wpf.dll")
  clr.AddReferenceByPartialName("PresentationCore")
  clr.AddReferenceByPartialName("PresentationFramework")
  clr.AddReferenceByPartialName("WindowsBase")
  clr.AddReferenceByPartialName("IronPython")
  clr.AddReferenceByPartialName("Microsoft.Scripting")
  
  import wpf 
  from System.Windows import Application, Window, Controls
  from System.Windows.Forms import Form, Button
  
  class NewWindow(Window):
      def __init__(self):
          wpf.LoadComponent(self, 'NewWindow.xaml')
  
      def CreateButtons_Click(self, sender, e):
          self.myButton = Button()
          self.myButton.Name="boton1"
          self.myButton.Text="prueba"
          self.myButton.Size = Size(75,23)
          self.myButton.Location = Point(0,0)
          #Add to grid
          self.grid.Children.Add(self.myButton)
  </code></pre>
  
  <p>That shows an error: </p>
  
  <blockquote>
    <p>expected UIElement, got Button</p>
  </blockquote>
  
  <p>If I skip that error and erase the line <strong>self.grid.Children.Add(self.myButton)</strong>, it doesnt get an error, but doesnt show any button either.</p>
  
  <p>How i can show my button in there by python code? <em>(New at python and wpf)</em></p>