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

标签 c# wpf mouseevent flowdocument tablerow

当在 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);
   }
}

请帮忙...

最佳答案

我知道有点晚了,你可能已经不在这里了,更不用说仍在这个项目中了,但对于那些将来可能会看到这个的人:要从每个单元格中获取数据,之后

TableRow tr = sender as TableRow;

执行如下操作:

// 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()));
}

阅读 FlowDocument 层次结构可能是个好主意。一个不错的起点是 MSDN's Documentation .

关于c# - 如何从 WPF 中 FlowDocument 的表中的 TableRow 获取 TableCell 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15571921/

相关文章:

c# - WPF 和 Prism 的通用对话框窗口

Python 诅咒 getmouse 函数?

c# - C# 中的三次鼠标单击?

c# - 使用从 WCF 生成的类与创建自己的模型 dll 的优缺点是什么?

C#:将文件拖放到 .exe(图标)上并获取文件路径

c# - 使用 Entity Framework 将 MySql 数据转换为 Microsoft Sql

WPF TextBox MenuItem 移动鼠标时失去焦点

c# - GridViewColumn autosize 只工作一次

python - Pygame 在全屏模式下不返回鼠标位置

C# MySQL 无法识别输入