2013-03-13 52 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; 

我希望這會幫助某人。