tags:

views:

34

answers:

0

I have a wpf datagrid where the columns have textbox cell template added. Data is populated from an xml source through a person class.

<Persons>
      <Person FirstName="John" LastName="Doe" Age="37", Sex="Male"/>
      <Person FirstName="Paul" LastName="Sams" Age="34", Sex="Male"/>
</Persons>

The datagridrow will be the person class shown below.

public class Person
{
     public string FirstName { get; set; }
     public string LastName { get; set; }
     public int Age { get; set; }
     public string Sex { get; set; }
}

Hence when I change the value of any cell during runtime, I want to save the changes back to the xml file. But the datagridrow returns the old value only.

Loading xml and access the data using LINQ:::

 XElement content = XElement.Load(path);
 var elements = from item in content.Elements("Person").Elements()
           select new Person
             {
                FirstName = item.Attribute("FirstName").Value,
                LastName = item.Attribute("LastName").Value,
                Age = item.Attribute("Age").Value,
                Sex = item.Attribute("Sex").Value,

             };

  grid.ItemsSource = elements;

Binding in xaml:::

 <DataGridTemplateColumn Header="First Name">
  <DataGridTemplateColumn.CellTemplate>
         <DataTemplate>
              <TextBox Text="{Binding FirstName}"/>
         </DataTemplate>
  </DataGridTemplateColumn.CellTemplate>
 </DataGridTemplateColumn>