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

C# 如何在WPF中的FlowDocument中从表中的TableRow获取TableCell值?,c#,wpf,mouseevent,flowdocument,tablerow,C#,Wpf,Mouseevent,Flowdocument,Tablerow,当在WPF中单击行时,我想从表格行获取所有数据 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 Ta

当在
WPF
中单击行时,我想从
表格行
获取所有数据

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()));
}
//我想您应该在这里开始列出
//它将保存循环结果的内容。
列表结果列表=新列表();
foreach(tr.Cells中的var tableCell)
{
//如果有多个块,可能需要在此处开始另一个列表。
列表块内容=新列表();
foreach(tableCell.Blocks中的var块)
{
//可能要在此处开始另一个列表,以便在下一个循环中添加到该列表。
List inlineContent=新列表();
foreach(在block.Inlines中内联变量)
{
//根据内联类型在此处实现任何内容,
//例如跨距、行程、InlineUIContainer等。
//我以为是短信。
添加(新的文本范围(inline.ContentStart,inline.ContentEnd.Text);
}
Add(string.Join(“,inlineContent.ToArray());
}
resultsList.Add(string.Join(“\n”,blockContent.ToArray());
}

阅读FlowDocument层次结构可能是个好主意。一个好的开始是。

我知道有点晚了,你可能还不在这里,更不用说还在这个项目上,但对于那些将来可能会看到这个的人来说:在

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()));
}
//我想您应该在这里开始列出
//它将保存循环结果的内容。
列表结果列表=新列表();
foreach(tr.Cells中的var tableCell)
{
//如果有多个块,可能需要在此处开始另一个列表。
列表块内容=新列表();
foreach(tableCell.Blocks中的var块)
{
//可能要在此处开始另一个列表,以便在下一个循环中添加到该列表。
List inlineContent=新列表();
foreach(在block.Inlines中内联变量)
{
//根据内联类型在此处实现任何内容,
//例如跨距、行程、InlineUIContainer等。
//我以为是短信。
添加(新的文本范围(inline.ContentStart,inline.ContentEnd.Text);
}
Add(string.Join(“,inlineContent.ToArray());
}
resultsList.Add(string.Join(“\n”,blockContent.ToArray());
}

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

对不起,这是.net 4.5版本,我使用的是4.0:(任何其他解决方案朋友,这里禁用了TableCell项属性。如何将其启用。TableRow tr=sender as TableRow;TableCellCollection tc=tr.Cells;//我无法访问tc.Item,因为它显示的错误如下..天哪!我在这个世界上是单身,因为没有人回答我的问题?:(您只能访问如上所述的TableCell,而不能访问段落或运行。要访问段落或运行,您应在创建新TableCell(新段落(new Run())之前为其指定每个名称。抱歉,这是.net 4.5版本,我使用的是4.0:(任何其他解决方案朋友,这里禁用了TableCell项属性。如何将其启用。TableRow tr=sender as TableRow;TableCellCollection tc=tr.Cells;//我无法访问tc.Item,因为它显示的错误如下..天哪!我在这个世界上是单身,因为没有人回答我的问题?:(您只能访问如上所述的TableCell,而不能访问段落或运行。要访问段落或运行,应在创建新TableCell(新段落(new Run())之前为其指定每个名称。).@SHINJaeGuk一般来说,您是正确的。您必须确定要处理哪种类型的
类型。它可能类似于
foreach(tableCell.Blocks.OfType()中的var Block)
例如,如果您使用类型为
,请确保在.cs文件的顶部放置一个使用System.Linq的
。@SHINJaeGuk一般来说,您是正确的。您必须确定要处理哪种类型的
类型。它可能类似于
foreach(tableCell.Blocks.OfType()中的var Block)
例如,如果您使用类型为
,请确保在.cs文件的顶部放置一个使用System.Linq的