Arun Prakash
Arun Prakash

Reputation: 121

WPF Displaying malayalam in TextBlock

I am working on a WPF app to extract title bar from a webpage (language is in Malayalam) and display on a textBlock. the problem am facing is on displaying the text (the Malayalam letters) are replaced with questions marks/registered logo sort of charterers.

how do i render malayalam font correctly in the WPF textBlock or a textbox ?

here is the XAML code for TextBlock

<TextBlock Name="media" TextWrapping="Wrap" />

here is the code for scraping the data from a site

using (WebClient client = new WebClient())
{
    var read = client.OpenRead(url);
    HtmlDocument doc = new HtmlDocument();
    doc.Load(read);
    var title = doc.DocumentNode.SelectSingleNode("//title").InnerText;
    string text = doc.DocumentNode.InnerHtml;

    media.Dispatcher.Invoke(() =>
    {
        media.Text = title + Environment.NewLine;
    });
}

The Result i get

Upvotes: 0

Views: 76

Answers (1)

Adam Jachocki
Adam Jachocki

Reputation: 2125

I think that your problem is not displaying the text in TextBlock, but getting it from the server. You should load the document with proper encoding, something like this:

WebClient client = new WebClient();
var data = client.DownloadData(url);
var html = Encoding.UTF8.GetString(data); //use proper encoding

Or try using HtmlAgilityPack

Upvotes: 2

Related Questions