【问题标题】:XAML tabular data viewXAML 表格数据视图
【发布时间】:2013-03-13 04:35:46
【问题描述】:

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

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 中是否有任何解决方法?另外我想为每一行添加功能,这样如果我点击一行,它就会转到一个特定的链接。

【问题讨论】:

标签: c# xaml view


【解决方案1】:

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

【讨论】:

    【解决方案2】:

    我使用 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;
    

    我希望这会对某人有所帮助。

    【讨论】:

      猜你喜欢
      • 2016-10-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-06-10
      • 1970-01-01
      相关资源
      最近更新 更多