How to show basic HTML Windows8 Metro style TextBl

2019-05-02 00:38发布

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.

2条回答
贼婆χ
2楼-- · 2019-05-02 01:10

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}}"

查看更多
狗以群分
3楼-- · 2019-05-02 01:19

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

查看更多
登录 后发表回答