简体   繁体   English

Windows Phone 8.1 html taqs rss应用程序

[英]windows phone 8.1 html taqs rss app

I want to ask is there any way to remove the html taq from Rss Reader on windows phone 8.1 I'm working on app that show the topics on any site using Rss on the smartphone " windows phone" but I have this problem can I remove the html taqs this pic will show u what I mean ?? 我想问是否有任何方法可以从Windows Phone 8.1上的Rss Reader中删除html taq,我正在使用可在智能手机“ Windows Phone”上使用Rss在任何站点上显示主题的应用程序,但是我有这个问题可以删除吗这个图片的HTML Taqs将告诉你我的意思? 问题删除html taqs

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

What control is this? 这是什么控制? Have you consider using a Web Browser control? 您是否考虑过使用Web浏览器控件? Or, if you really need to display it in a TextBox (assuming it's a TextBox), you can convert your HTML into a XAML FlowDocument, using this tutorial . 或者,如果您确实需要在TextBox中显示它(假设它是TextBox),则可以使用本教程将HTML转换为XAML FlowDocument。

I follow the same tutorial for create my rss reader. 我遵循相同的教程来创建我的rss阅读器。 So, for remove the html code you need create a class to trimmer the description: Create a class named RssTextTrimmer.cs with the code: 因此,要删除html代码,您需要创建一个类来简化描述:使用以下代码创建一个名为RssTextTrimmer.cs的类:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Globalization;
using System.Text.RegularExpressions;
using Windows.UI.Xaml.Data;
using System.Net;

namespace VEJA_Notícias
{
public class RssTextTrimmer : IValueConverter
{


    public object Convert(object value, Type targetType, object parameter, string language)
    {
        if (value == null) return null;

        int maxLength = 200;
        int strLength = 0;
        string fixedString = "";

        // Remove HTML tags. 
        fixedString = Regex.Replace(value.ToString(), "<[^>]+>", string.Empty);
        // Remove newline characters.
        fixedString = fixedString.Replace("\r", "").Replace("\n", "");

        // Remove encoded HTML characters.
        fixedString = WebUtility.HtmlDecode(fixedString);

        strLength = fixedString.ToString().Length;

        // Some feed management tools include an image tag in the Description field of an RSS feed, 
        // so even if the Description field (and thus, the Summary property) is not populated, it could still contain HTML. 
        // Due to this, after we strip tags from the string, we should return null if there is nothing left in the resulting string. 
        if (strLength == 0)
        {
            return null;
        }

        // Truncate the text if it is too long. 
        else if (strLength >= maxLength)
        {
            fixedString = fixedString.Substring(0, maxLength);

            // Unless we take the next step, the string truncation could occur in the middle of a word.
            // Using LastIndexOf we can find the last space character in the string and truncate there. 
            fixedString = fixedString.Substring(0, fixedString.LastIndexOf(" "));
        }

        fixedString += "...";

        return fixedString;
    }

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

And in your MainPage.xaml you need add the code: 在您的MainPage.xaml中,您需要添加以下代码:

<Page.Resources>        
    <local:RssTextTrimmer  x:Key="RssTextTrimmer" />
</Page.Resources>

To access the method of RssTextTrimmer class in the xaml textblock you need to do so: 要访问xaml文本块中RssTextTrimmer类的方法,您需要这样做:

<TextBlock x:Name="textTitulo" Text="{Binding title, Converter={StaticResource RssTextTrimmer}}"/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM