Ramesh Ramesh - 1 year ago 107
C# Question

XAML tabular data view

I am developing Windows Store app using C# and XAML. I am displaying data in a text block called

in the following code.

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}",
"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}",

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


But it is not looking good; I want to have tabular data view which looks good. Is there any workaround in XAML? Also I would like to add functionality to each row so that if I click a row, It goes to a particular link.

Answer Source

I used Listbox as follows to give the required view.

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



                                <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}"  />


and for code behind C# as follows.

ResultListBox.ItemsSource = qualityRecordsRootObject.auditDTOList;

I hope this would help someone.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download