2013-03-13 71 views
0

我正在使用C#和XAML开发Windows应用商店应用程序。我在下面的代码中将数据显示在名为greetingOutput的文本块中。XAML表格数据视图

try 
{ 
    var response = navigationParameter.ToString(); 

    var serializer = new DataContractJsonSerializer(typeof(QualityRecordsRootObject)); 
    var stream = new MemoryStream(Encoding.UTF8.GetBytes(response)); 
    QualityRecordsRootObject qualityRecordsRootObject = (QualityRecordsRootObject)serializer.ReadObject(stream); 

    greetingOutput.Text = String.Format("{0,60}{1,60}{2,60}{3,60}", 
          "Brand", 
          "Printer", 
          "Printer Location", 
          "Date Received"); 

    greetingOutput.Text += "\n\n"; 




    for (int i = 0; i < qualityRecordsRootObject.auditDTOList.Count(); i++) 
    { 
     greetingOutput.Text += String.Format("{0,60}{1,60}{2,60}{3,60}", 
         qualityRecordsRootObject.auditDTOList[i].brandName, 
         qualityRecordsRootObject.auditDTOList[i].printerName, 
         qualityRecordsRootObject.auditDTOList[i].printerLocationName, 
         qualityRecordsRootObject.auditDTOList[i].receivedDate); 

     greetingOutput.Text += "\n"; 
    } 
} 
catch (Exception ex) 
{ 
    Debug.WriteLine("exception: " + ex.Message); 
    greetingOutput.Text += " No Records Found!"; 

} 

但它看起来不好;我想要表格数据视图看起来不错。 XAML有没有解决方法?此外,我想添加功能到每一行,以便如果我点击一行,它会转到特定的链接。

+1

我编辑了你的标题。请参阅:“[应该在其标题中包含”标签“](http://meta.stackexchange.com/questions/19190/)”,其中的共识是“不,他们不应该”。 – 2013-03-13 04:44:41

+0

我想要像这样的表格视图http://msdn.microsoft.com/en-us/library/ms750416.aspx但我想知道如何使用XAML绑定数据。此外,我希望每一行都是可点击的。 – Ramesh 2013-03-13 04:51:37

回答

0

我用Listbox如下给出所需的视图。

<ListBox Name="ResultListBox" 
     Height="500" Width="1000" Margin="0,20,0,0" HorizontalAlignment="Left" VerticalAlignment="Top" 
     Visibility="Visible" SelectionChanged="ResultListBoxSelectionChanged" 
      > 

        <ListBox.ItemTemplate> 

         <DataTemplate> 

           <StackPanel Orientation="Horizontal"> 

           <TextBlock Width="250" Text="{Binding brandName}" /> 
           <TextBlock Width="250" Text="{Binding printerName}" /> 
           <TextBlock Width="250" Text="{Binding printerLocationName}" /> 
           <TextBlock Width="250" Text="{Binding receivedDate}" /> 

       </StackPanel> 
     </DataTemplate> 
    </ListBox.ItemTemplate> 
</ListBox> 

以及C#后面的代码,如下所示。

ResultListBox.ItemsSource = qualityRecordsRootObject.auditDTOList; 

我希望这会帮助某人。