2016-11-13 2 views
0

J'ai une liste de fichiers xml. (lecture d'un répertoire) Je veux afficher tous les enregistrements présents dans chaque fichier XML dans DataGrid.chargement de plusieurs fichiers xml dans datagrid

ici est le code pour le même (fichier XAML)

<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Path=Elements[TestResult]}" x:Name="dataGrid" Margin="10,0,-1,0"> 
         <DataGrid.Columns> 
          <DataGridTextColumn Header="TestCaseId" Binding="{Binding Path=Attribute[TestCaseId].Value}" /> 
          <DataGridTextColumn Header="Outcome" Binding="{Binding Path=Attribute[Outcome].Value}"/> 
          <DataGridTextColumn Header="Duration" Binding="{Binding Path=Attribute[Duration].Value}"/> 
          <DataGridTextColumn Header="Comment" Binding="{Binding Path= Attribute[Comment].Value}"/> 
         </DataGrid.Columns> 
        </DataGrid> 

TestResult Classe

class TestResult 
{  
     [XmlAttribute("TestCaseId")] 
     public string TestCaseId { get; set; } 

     [XmlAttribute("Outcome")] 
     public string Outcome { get; set; } 

     [XmlAttribute("Duration")] 
     public string Duration { get; set; } 

     [XmlAttribute("Comment")] 
     public string Comment { get; set; } 
    } 
Here is the code for loading each file in to datagrid 

mais je peux en mesure de voir seulement dernières données du fichier

foreach (string item in Files) 
     { 

      var peopleList = XElement.Load(item); 
      this.dataGrid.DataContext = peopleList; 

     } 

Voici le un fichier xml

<TestResults URL="https://google.com/" StartDateTime="2016-11-11T14:52:25.2499848+05:30"> 
<TestResult TestCaseId="Smoke_21949" Outcome="Pass" Duration="00:03:09.9335101" Comment="" /> 
<TestResult TestCaseId="Smoke_31234" Outcome="Pass" Duration="00:02:56.1503179" Comment="" /> 
</TestResults> 

Répondre

1

Vous devez créer une liste et ajouter à la liste,

var peopleList = new List<XElement>(); 
foreach (string item in Files) 
    { 
     peopleList.Add(XElement.Load(item));   
    } 
this.dataGrid.DataContext = peopleList; 
+0

tout changement XAML? à cette ligne ItemsSource = "{Binding Path = Elements [TestResult]}" – user3652040

+0

vous ne pouvez pas définir directement this.dataGrid.ItemsSource = peopleList; retirer de xaml – Sajeetharan

+0

Non mon pote de travail :( – user3652040