将标签上的字符串拆分为多个文本框
我不再纠结去哪里寻找解决方案。
我有一个包含标签 "< p >"
和 "< /p >" 以及 "< h1>" 的字符串和“”对于标题,以及“”用于链接。该字符串通过 app.current 传递到第二页,当我将其设置为文本块的源时,我看到了整个字符串。
现在我的问题: 我想在每个“< p>”上创建一个新的 TextBlock,其中包含直到“< /p>”的文本。标题也是如此,因为我想以不同的方式设置它们的样式。我想在列表中查看的链接。
我尝试了几件事,但没有找到有效的解决方案。我的最后一次尝试是使用这个http://www.eugenedotnet.com/2011/04/binding-text-containing-tags-to-textblock-inlines-using-attached-property-in-silverlight-for-windows-phone- 7/。我无法根据我的需要更改此设置。
我想从我的字符串创建子字符串,并为每个子字符串使用/或新的 TextBlock 进行新的运行。没弄清楚。
我对此确实没有任何想法。有人有什么想法吗?
I do not knot where to search anymore for a solution.
I have a string which contains tags "< p >"
and "< /p >", as well as "< h1>" and "< /h1>" for headers, and "< a>< /a>" for links. The string is passed via app.current to a second page, when i set it as source of a textblock I see my whole string.
Now my Problem:
I want to create a new TextBlock on every "< p>", which contains the text until "< /p>". Same for the headers, as I want to style them differently. The links I want to see in a list.
I tried several things, but found no working solution. My last try was to work with this http://www.eugenedotnet.com/2011/04/binding-text-containing-tags-to-textblock-inlines-using-attached-property-in-silverlight-for-windows-phone-7/. I was not able to change this for my needs.
I wanted to create substrings from my string, and for each substring a new run with/or a new TextBlock. Did not figure it out.
I really do not have any ideas left for this. Anyone any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我建议使用
HtmlAgilityPack
来解析 HTML。获取适用于 WP7 的 HtmlAgilityPack 的最简单方法是安装 NuGet,右键单击您的
References
并选择“管理 NuGet 包”,然后在“在线”中搜索HtmlAgilityPack
。I'd recommend using
HtmlAgilityPack
to parse the HTML.The simplest way to get HtmlAgilityPack for WP7 is to install NuGet, right click your
References
and select "Manage NuGet Packages" and then search "Online" forHtmlAgilityPack
.为了稍微扩展 Richard Szalay 的答案,NuGet 上的 HTML Agility Pack 版本似乎不包含添加的 WP7 特定实现。在 这个问题中,有一个对 HAPPhone 版本的参考,可以从HTML AGility Pack 项目页面,并且非常有效电话里很好。
不幸的是,您必须下载源代码并自行构建/手动添加引用。我想 NuGet 版本会及时更新,但当我上周这样做时,这是唯一的方法。
To expand slightly on Richard Szalay's answer, the version of the HTML Agility Pack on NuGet doesn't seem to include the WP7 specific implementation that was added. In this question there is a reference to the HAPPhone version which can be downloaded from the HTML AGility Pack project page, and works very well on the phone.
Unfortunately, you'll have to download the source and build it yourself / add the reference manually. I guess the NuGet version will be updated in time, but when I did this last week it was the only way.