wpf:检查 Span 中有多少个组件?

发布于 2024-08-03 23:24:13 字数 181 浏览 4 评论 0原文

我有 WPF Span,用作 TextBlock 的源。我正在做一些测试,在代码中了解 Span 内部有多少种类型的组件将非常有帮助。

例如,在某一时刻,我将一个新的 Bold() 插入到跨度的内联中。我如何检查跨度内是否恰好包含一个 Bold 组件?

我不太确定如何搜索 Span.Inlines 来检索这个数字。

I have WPF Span that is used as a source to a TextBlock. I am doing some tests and it would be very helpful to know in code how many of which type of component is inside of the Span.

For example, at one point I insert a new Bold() into the span's inlines. How would I check that there is exactly one Bold component contained inside of the span?

I'm not too sure how to search Span.Inlines to retrieve this number.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一杆小烟枪 2024-08-10 23:24:13

您可以迭代 SpanInlines 属性:

int count = 0;
foreach(Inline inline in span.Inlines)
{
    if (inline is Bold) count++;
}

You can iterate over the Inlines property of the Span :

int count = 0;
foreach(Inline inline in span.Inlines)
{
    if (inline is Bold) count++;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文