简体   繁体   English

如何从WPF中FlowDocument的表中的TableRow中获取TableCell值?

[英]How to get TableCell Value from TableRow in Table at FlowDocument in WPF?

I want to get all the data from a TableRow , when row is clicked in WPF . 我想从WPF单击行时从TableRow获取所有数据。

currentRow = tab.RowGroups[0].Rows[r];
currentRow.MouseLeftButtonDown += new MouseButtonEventHandler(test);

void test(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
   try 
   {
      TableRow tr = sender as TableRow;
      // After that what i do to read TableCell Value
   } 

   catch(Exception ex) 
   {
       MessageBox.Show(ex.Message);
   }
}

Please help... 请帮忙...

I know it's a little late, and you're probably not still here, let alone still on this project, but for those who might view this in the future: To get the data from each cell, after 我知道已经有点晚了,您可能还没来这里,更不用说仍然在这个项目上了,但是对于那些将来可能会看到的人来说:

TableRow tr = sender as TableRow;

do something like the following: 请执行以下操作:

// I imagine you'd want to start a list here
// that will hold the contents of your loops' results.
List<string> resultsList = new List<string>();
foreach(var tableCell in tr.Cells)
{
    // May want to start another list here in case there are multiple blocks.
    List<string> blockContent = new List<string>();
    foreach(var block in tableCell.Blocks)
    {
        // Probably want to start another list here to which to add in the next loop.
        List<string> inlineContent = new List<string>();
        foreach(var inline in block.Inlines)
        {
            // Implement whatever in here depending the type of inline,
            // such as Span, Run, InlineUIContainer, etc.
            // I just assumed it was text.
            inlineContent.Add(new TextRange(inline.ContentStart, inline.ContentEnd).Text);
        }
        blockContent.Add(string.Join("", inlineContent.ToArray()));
    }
    resultsList.Add(string.Join("\n", blockContent.ToArray()));
}

It might be a good idea to read up on the FlowDocument hierarchy. 阅读FlowDocument层次结构可能是一个好主意。 A decent place to start is MSDN's Documentation . 一个合适的起点是MSDN的Documentation

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM