Windows8:去掉文本中的HTML标记 (后台一句代码的事儿)

1、在界面中放一个TextBox,用来输入带HTML的文本,一个Button,点击后转换,一个TextBlock,显示转换后的字符串。XAML如下:

<Page

x:Class="App1.MainPage"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:local="using:App1"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

mc:Ignorable="d">

<GridBackground="{StaticResource ApplicationPageBackgroundThemeBrush}">

<Grid.RowDefinitions>

<RowDefinition/>

<RowDefinitionHeight="Auto"/>

<RowDefinition/>

</Grid.RowDefinitions>

<TextBoxx:Name="txtInput"Grid.Row="0" TextWrapping="Wrap"/>

<ButtonGrid.Row="1" Margin="5,12,0,13" Content="转换" Click="onClick"/>

<ScrollViewerGrid.Row="2" VerticalScrollBarVisibility="Visible"HorizontalScrollMode="Enabled">

<TextBlockx:Name="tbResult"FontSize="24"TextWrapping="Wrap"/>

</ScrollViewer>

</Grid>

</Page>

 

后台代码:引入Windows.Data.Html命名空间

private void onClick(object sender, RoutedEventArgs e)

{

this.tbResult.Text = HtmlUtilities.ConvertToText(this.txtInput.Text);

 

现在就可以运行查看效果啦!!!

posted @ 2012-12-20 19:44  刘祎  阅读(174)  评论(0编辑  收藏  举报