How to show basic HTML Windows8 Metro style TextBlock?

北战南征 提交于 2019-12-10 05:48:04

问题


I have an html page that only contains <p>, <strong>, <br /> and <a> tags. I want to show this content in a XAML TextBlock in Windows 8. Is there any way to show that content in a TextBlock without losing the structure (e.g. paragraphs)? I don't want to use WebView because WebView can not be transparent.


回答1:


I am developing a open source Windows 8 Metro RSS Reader app and I used HtmlUtilities.ConvertToText

You can see the source code implementation here http://metrorssreader.codeplex.com/SourceControl/changeset/view/17913#265003




回答2:


If you want to do it in XAMl, just add a converter.

    public sealed class TextToHtmlConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string language)
    {
        if (value is string)
        {
            return HtmlUtilities.ConvertToText(value.ToString());
        }
        else
        {
            return value;
        }
    }

    public object ConvertBack(object value, Type targetType, object parameter, string language)
    {
        throw new NotImplementedException();
    }
}

Then in your XAML add a resource reference.

Then Bind with a converter:

Text="{Binding titleFull,Converter={StaticResource TextToHtmlConverter}}"



来源:https://stackoverflow.com/questions/11491134/how-to-show-basic-html-windows8-metro-style-textblock

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!