如何在WPF的FlowDocument中从表中获取表单元值
本文关键字:获取 表单 单元 WPF FlowDocument | 更新日期: 2023-09-27 18:05:32
我想从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 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的Documentation是一个不错的开始。