本文介绍了[UWP]使用xaml和c#将html语言显示到textblock或richtextblock中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我有一个使用HTML语言的文本,如下所示:<p style="text-align: justify;"><span style="font-family: arial, helvetica, sans-serif; font-size: medium;">Among various furniture manufacturer from Indonesia which consistently export to the whole world, Jepara is known by its highly productivity of furniture. As the country which is rich of wooden resources, Indonesian craftsmen, especially from Jepara were trained well in how to make beautiful furnitures along with its functions. Each furniture manufacturer trying to producing their best quality whether from its special designs nor furniture material’s quality.</span></p> <p style="text-align: justify;"><span style="font-family: arial, helvetica, sans-serif; font-size: medium;">For some people who loves collecting furniture, antique furniture is one of furniture products that oftenly hunted. This traditional furniture style is also known with other similar types such as French furniture, or antique reproduction. There are several craftsmen in Jepara produce that kinds of furniture. Such as Bina Antiek, more than 17 years running furniture business which has exported its products through many countries in the world. This furniture company has specialize in antique reproduction furniture and colonial furniture style. All furniture products are carved by skilled craftsman and produces fine quality furniture products.</span></p> <p style="text-align: justify;"><span style="font-family: arial, helvetica, sans-serif; font-size: medium;">“We only focused in export furniture. We have been exporting our products to many countries, especially to Europe and America where consistently repeat order in every month” Zazuli, the owner of Bina Antiek said, when asked by Indonesia-Product.com team about furniture’s market. He also explains what kinds of furniture that produced by Bina Antiek, so that products to be able to penetrate the export market. Recently, Bina Antiek launched their new product “White and Iron Furniture”. So, what makes their products different from other furniture manufacturer are the main concept is using recycle wood materials such as, natural recycle pines and recycle teak with by accentuating the aura of wood.</span></p> <p style="text-align: justify;"><span style="font-size: medium;">“How could Bina Antiek succeed by only running the export company? ” that kinds of question usually often comes in our mind. “We’ve joined Indonesia Product Global Group more than 17 years, and was grateful since promoted by them through the website, we regularly get buyers from abroad as we expected”, Zazuli said. From that lines, the owner of Bina Antiek is very appreciate of digital marketing because it could be a bridge between producer and buyer with ease. He also told why Bina Antiek decide to join in Indonesia Product Global Group is because they proven focus on Indonesian products and actually promote abroad. This is what is required by all businesses in Indonesia's economic growth nowadays.</span></p> <p style="text-align: justify;"><span style="font-size: medium;"><br /></span></p> <p style="text-align: justify;"><span style="font-size: medium;"><br /></span></p> <p style="text-align: justify;"><span style="font-size: medium;">More info visit <span style="color: #ff0000;"><em><strong>www.indonesia-product.com</strong></em></span></span></p> <p style="text-align: justify;"><span style="font-size: medium;"> </span></p> <p style="text-align: justify;"><span style="font-size: medium;"> </span></p> <pre><span style="font-size: medium;"> </span></pre> JSON的示例: XAML:<ScrollViewer x:Name="articleContentScroll1" Grid.Row="6" Margin="10,15,10,10" Width="650" Height="150" VerticalAlignment="Top" HorizontalAlignment="Left" VerticalScrollBarVisibility="Auto" VerticalScrollMode="Auto" Background="{x:Null}" HorizontalScrollMode="Disabled"> <TextBlock x:Name="articleContentDetail" Margin="0,0,15,15" FontSize="15" FontFamily="Segoe UI Black" FontWeight="SemiLight" TextWrapping="Wrap" Height="auto" TextAlignment="Justify"/></ScrollViewer>代码:try { string urlPath = "http://.../articles/" + articleIdDetail.Text + ".json?module=articles&page=1&token=3f63-dc43-c8d5-eb45-8cbf-b72d-9d98-800f"; var httpClient = new HttpClient(new HttpClientHandler()); var values = new List<KeyValuePair<string, string>> { }; HttpResponseMessage response = await httpClient.GetAsync(urlPath); response.EnsureSuccessStatusCode(); if (!response.IsSuccessStatusCode) { articleDetailLoading.IsActive = false; RequestException(); } string jsonText = await response.Content.ReadAsStringAsync(); JsonObject jsonObject = JsonObject.Parse(jsonText); JsonObject jsonData = jsonObject["data"].GetObject(); JsonObject groupObject1 = jsonData.GetObject(); string content = groupObject1["content"].GetString(); ArticleClass file = new ArticleClass(); articleContentDetail.Text = file.content; articleDetailLoading.IsActive = false; } catch (HttpRequestException ex) { articleDetailLoading.IsActive = false; } } 我想使用XAML和C#将其显示到TextBlock或Richtextbloack中。怎么样? 注意:数据来自使用数据绑定的JSON。推荐答案要显示HTML,请使用WebView控件。要在TextBlock中显示,您需要解释HTML。有几个第三方和(我认为)开源HTML解析库,你可以搜索帮助。To display HTML use a WebView control. To display in a TextBlock you'll need to interpret the HTML. There are several third party and (I think) open-source HTML parsing libraries you can search for to help. 这篇关于[UWP]使用xaml和c#将html语言显示到textblock或richtextblock中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-25 13:19