获取包含 Block 对象的 BlockCollection 对象
获取包含给定块类型对象的 BlockCollection 对象(System.Windows.Documents 命名空间)的最简单(可能也更快)的方法是什么?
我找不到使用 Block 类上可用的任何直接方法来执行此操作。
public static BlockCollection FindContainingCollection(Block block)
{
// ???
}
What would be the easiet (and possibly fast) way to get a BlockCollection object (System.Windows.Documents namespace) which contains a given Block-type object?
I could not find any direct way of doing this using what's available on Block class.
public static BlockCollection FindContainingCollection(Block block)
{
// ???
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
因为我发布这篇文章已经一个月了,但没有得到答复,我将发布我最终做了什么。我这样写是相当愚蠢的,但我找不到任何更干净的方法来实现它,主要是因为 Blocks 属性不是通过公共接口公开的。
Because It's been a month since I posted this and got no answer, I'll post what I ended up doing. It's rather silly that I wrote this way, but I could not figure out any cleaner way to implement it, mainly because Blocks property is not exposed through a common interface.
使用 ElementAt(int32)
Use ElementAt(int32)
Block 有一个属性 SiblingBlocks 可以满足您的需要。
https:// msdn.microsoft.com/en-us/library/system.windows.documents.block.siblingblocks(v=vs.100).aspx
Block has a property SiblingBlocks which does what you need.
https://msdn.microsoft.com/en-us/library/system.windows.documents.block.siblingblocks(v=vs.100).aspx