title: Dynamic WPF generation with Linq to XML
body: <p>I have been trying to create some dynamic Xaml. </p>
  
  <p>I have the following c#</p>
  
  <pre><code>private void LoadUI()
  {
      XNamespace xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation";
  
      dynamic UI = new XElement(xmlns + "Grid",
                                new XAttribute(XNamespace.Xmlns + "x", "http://schemas.microsoft.com/winfx/2006/xaml"),
                                new XAttribute("Name", "Grid1"),
                                new XElement(xmlns + "Grid.ColumnDefinitions",
                                             new XElement(xmlns + "ColumnDefinition", new XAttribute("Width", "100*")),
                                             new XElement(xmlns + "ColumnDefinition", new XAttribute("Width", "200*"))),
                                new XElement(xmlns + "StackPanel", new XAttribute("Name", "StackLabels"),
                                             new XAttribute("Margin", "3"),
                                             from column in this.TableSchema
                                             where column.IsPrimaryKey == 0 &amp;&amp; column.DataType != "timestamp"
                                             select
                                                 new XElement(xmlns + "Label", new XAttribute("Height", "28"),
                                                              new XAttribute("Name", column.ColumnName + "Label"),
                                                              new XAttribute("HorizontalContentAlignment", "Right"),
                                                              column.ColumnName)),
                                new XElement(xmlns + "StackPanel",
                                             new XAttribute("Grid.Column", "1"),
                                             new XAttribute("Name", "StackFields"),
                                             new XAttribute("Margin", "3")
                                    ,
  
                  from column in this.TableSchema
                  where column.IsPrimaryKey == 0 &amp;&amp; column.DataType != "timestamp"
                  select
                  GetUIElement(column)));
  
      this.DynamicContent.Content = XamlReader.Load(UI.CreateReader());
  
  }
  </code></pre>
  
  <p>The error i get is in trying to create the Grid.Column. The exact error is 
  {"Der unbekannte Member \"Grid.Column\" kann nicht festgelegt werden."}</p>
  
  <p>so it doesn't know the Grid.Column...</p>
  
  <p>Anyone any ideas?</p>
  
  <p>It works fine with the new XAttribute("Grid.Column", "1"), line commented out just doesn't show what I want naturally!</p>
  
  <p>The generated Grid looks like the following:</p>
  
  <pre><code> &lt;Grid xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" Name="Grid1"   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"&gt;
    &lt;Grid.ColumnDefinitions&gt;
      &lt;ColumnDefinition Width="100*" /&gt;
      &lt;ColumnDefinition Width="200*" /&gt;
    &lt;/Grid.ColumnDefinitions&gt;
    &lt;StackPanel Name="StackLabels" Margin="3"&gt;
      &lt;Label Height="28" Name="NummerLabel" HorizontalContentAlignment="Right"&gt;Nummer&lt;/Label&gt;    
    &lt;/StackPanel&gt;
    &lt;StackPanel Grid.Column="1" Name="StackFields" Margin="3"&gt;
      &lt;TextBox Height="28" Name="txtNummer" Text="{Binding Path=Nummer}" /&gt;
      &lt;/StackPanel&gt;
      &lt;/Grid&gt;
  </code></pre>