首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >XAML表格数据视图

XAML表格数据视图
EN

Stack Overflow用户
提问于 2013-03-13 12:35:46
回答 2查看 248关注 0票数 0

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

代码语言:javascript
复制
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中有什么变通方法吗?此外,我想添加每一行的功能,以便如果我单击一行,它会转到一个特定的链接。

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2013-03-19 16:44:44

我使用列表框提供所需的视图,如下所示。

代码语言:javascript
复制
<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#后面的代码,如下所示。

代码语言:javascript
复制
ResultListBox.ItemsSource = qualityRecordsRootObject.auditDTOList;

我希望这能帮助到一些人。

票数 0
EN

Stack Overflow用户

发布于 2013-03-14 01:10:45

我会使用DataGrid。这是DataGrid的msdn:http://msdn.microsoft.com/en-ca/library/system.windows.forms.datagrid.aspx

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/15377169

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档