Android Webview equivalent in Windows Phone 8 app - c#

I have text with some HTML tags in it.
Example : <I> I Play Football and Cricket </I>
Now when i try to display this text in Textblock it displays with Italics tag <I> as well.
The data is present in the XML file and i am working on Windows Phone 8 application.
In Android we use Webview, but what do i need to use here ?
EDIT
I have tried using TextBlock with inlines:
Italic itlText = new Italic();
itlText.Inlines.Add(new Run() { Text = "This is some example text in italics" });
Inilinetext.Inlines.Add(itlText);
It works good But issue here is suppose i have a text like below.
"This is text in <I>Italics</I> here"
Now it display entire text in italics.

This depends on how much content you want to display. If you will show large amount of HTML text, use WebBrowser control for that.
In case you only have a couple of tags i, em, b or strong, then you can actually use TextBlock, but you would have to do the parsing yourself then in order to convert the HTML to the suitable XAML components.
You also have to ask yourself how many such controls you need to display on a single page. If the answer is a few, use the WebBrowser then. If you need to display lots of them, say you have a chat or a feed, then the second route would be better.
EDIT:
Use the following code:
Inilinetext.Inlines.Add(new Run() { Text = "This is text in " });
Inilinetext.Inlines.Add(new Run() { Text = "Italics", FontStyle = FontStyle.Italic });
Inilinetext.Inlines.Add(new Run() { Text = " here" });
I told you you have to parse the original string to see which parts are italic and which are not.

Related

Xamarin.Forms Embed phone # hyperlinks (0 to many) in text

I have a requirement that I provide a dialog that will display some text. In this text, there may or may not be phone numbers.
I have the regex for recognizing these phone numbers, so I know where they are.
I do not know of any solution to provide a way that the user click on the phone numbers and perform an action (the action will be launch the phone app, which I already have code for).
It appears that you cannot format portions of a label or editor, nor embed hyperlinks.
If I want to preserve the text format (not break it up) do I have no option other than handle a click on the entire label?
My only other idea was to take the text, parse the phone numbers, and dynamically create multiple labels, with each phone number being it's own separate label, which I could format as bold and provide a tap gesture action. The problem with this is the formatting.
Are there any other solutions that I am not seeing?
I found a solution using WebView thanks to the comment suggestion from Gusman.
I replace the phone numbers in the text with html anchors like so
555.555.5555 - > <a href='555.555.5555'>555.555.5555></a>
I then handle the OnNavigating event, cancel the request, and instead open up the phone with the phone number obtained from the url.
WebView:
<WebView x:Name="EmergencyContactInfoWebView" HorizontalOptions="Center" HeightRequest="150" Navigating="OnNavigating">
</WebView>
OnNavigtaing event handler:
protected void OnNavigating(object sender, WebNavigatingEventArgs e)
{
e.Cancel = true; //cancel request
int separatorIdx = e.Url.LastIndexOf('/');
string phoneNumber = e.Url.Substring(separatorIdx+1); //parse phone number href from url
var phoneDialer = CrossMessaging.Current.PhoneDialer;
if (phoneDialer.CanMakePhoneCall)
{
phoneDialer.MakePhoneCall(phoneNumber); //make the call (using a xamarin forms plugin)
}
}

C# Winforms Help Text Change font

I have a little help pop-up that displays some text when the user presses a "?" label next to a drop-down to explain the different selections.
I did it using the Help.ShowPopup command since that seemed the easiest.
I was hoping there was a way to add different font properties to parts of the text or at least to the whole thing without having to go the direction of a CHM/HTML help-file.
Here is what I am trying to do:
private void helpLbl_Click(object sender, EventArgs e)
{
// for some reason, it ignores the 'parent' parameter
// and lays it out on the screen's coordinates
Point helpLocation = helpLbl.PointToScreen(Point.Empty);
helpLocation.Y += helpLbl.Height; // have it display underneath the control
Help.ShowPopup(this, // hosting form
#"<b>Fixed:</b>
Removes a fixed amount from the sale
<b>Percent Value:</b>
Removes a set percentage of the selected package from the sale
...", helpLocation);
I was hoping since there's the option to use an HTML document to display the help, I could use HTML tags to format what was being displayed, but it doesn't appear so. Any ideas?
Is there a way to do something like displaying a RichTextBox in the help pop-up?
Another possibility is generating a HTML document on-the-fly, but it asks for a "url" if I'm not supplying the text directly and I think that might be a little over-kill for the small amount I'm trying to do here.
You have two options. One is to use a WebBrowser Control. This natively accepts HTML and displays it. The problem with it is its kind of bloated just to use as a simple label.
Your second option is to simply create a RichTextLabel, simply like this:
public class RichTextLabel : RichTextBox
{
public RichTextLabel()
{
BorderStyle = BorderStyle.None;
}
}
Add this to your form and set the Rtf property to your RTF code. You will have to convert your HTML to RTF, which is easy if you got a program such as Microsoft Word, for example.

How to make sure that my <br> tag get read as a html and not as text

I have a asp.net page. On one particular page i can add comments and when i add these comments they get saved to a db. When i want new lines the "\n" tagg is automaticly displayed when i look at it in my backend code.
So now when i get back a response i want to get my comments back but i want them to have breaking spaces on those particular places where the "\n" is displayed.
I tried this in my backend code(cs):
Text = text.replace("\n", "<br/>")
the result i get:
my test<br/> test text new line<br/>
My <br> tags get displayed as text.
To clarify i basicly wan to achieve this:
Why are my "<br />" tags getting converted to "<br />"?
But from the backend code in C#.
Ive been googling and haven't been able to find a answer to this.
If you are using ASP.NET WebForms and you are putting the text in a Label control, this is normal behaviour. The Label control html-encodes its text before rendering it.
The Literal control does not use html-encoding, so if you change your Label to a Literal, it should work.
If you are using ASP.NET MVC, try using #Html.Raw(Model.Text).
You need to create an HtmlString with your content before printing it. So your code would be like
var foo = new HtmlString(text.replace("\n", "<br/>"));
and you would print foo.

How to find the font-name,size,style, text color from rich text-box text in c#

In my application I have a rich text-box.I use that as a text editor. I can change font,size, style when I needed. now my problem is I want to find out font-name,size, text-color of each character ?
i,e i want to retrieve every character's font-name,size, text-color after editing is done.
You can use the SelectionFont property to retrieve the font of the currently selected text. Similarly, you can use the SelectionColor property.
Never done this personally and no time to test at the moment, but the: Groups RV's DotNET forum may have your solution. Perhaps something like mentioned in the post:
for (int iCurChar = lastChar; iCurChar
richTextBox1.Text.Length; iCurChar++)
{
richTextBox1.Select(iCurChar,1);
char CurrChar = richTextBox1.Text[iCurChar];
Color CurrColor = richTextBox1.SelectionColor;
Font CurrFont = richTextBox1.SelectionFont;
float fontSize = CurrFont.Size
}
Taking a look at the Font class may be useful as well: Microsoft's Font Reference Page

Using <br/> in tool tip and change the default color of a tool tip

I am using default asp.net ToolTip property, the text is
This is Going to be a long text
Thats why we decided to split it.
but using <br/> to split the line doesn't work, it renders as a text, and I want it to break the line instead.
Here is my code:
Label lblActionText = new Label();
lblActionText.Text = "Helloooo Phaltu";
lblActionText.Style.Add("cursor", "pointer");
lblActionText.ToolTip =
"This is Going to be a long text"
+ "<br/>"
+ "Thats why we decided to split it.";
I've not tried this but would "System.Environment.NewLine" not do the job instead of the BR tag?
You can use this to insert a line break inside a ToolTip.
lblActionText.ToolTip = " First text " + Environment.NewLine + " second text ";
Use the line break character entity (
). It is easy to implement but the only problem is that this will work in IE & Chrome but not Firefox.
lblActionText.ToolTip = "This is Going to be a long text
Thats why we decided to split it.";
See jsFiddle: http://jsfiddle.net/jafLf/
You are passing a string value to a Tooltip, and that's why the HTML element <br /> is not working.
However you can try this ASP.Net AJAX TooltipExtender
This works only on IE but other browsers are not!!
If you want to have a customize tooltip then seach for jQuery tooltips to have a formatted tooltip
You can do this with adding a table in the tooltip :)
Example: ASP forum
The ASP.NET ToolTip property corresponds to the HTML title attribute.
In IE and Chrome you can simply do:
<span title="multiline
tool
tip">Mouseover me!</span>
However, that won't work in Firefox as it actually follows the W3C guidelines for CDATA.
CDATA is a sequence of characters from
the document character set and may
include character entities. User
agents should interpret attribute
values as follows:
Replace character entities with characters,
Ignore line feeds,
Replace each carriage return or tab with a single space.
Your best bet (considering you also want to change the colour) would be to go with a jQuery solution such as QTip which gives you all the customisation you want and more..
You cannot change the color of a tooltip with the default title attribute. For that the only way is to use a javascript generated tooltip.
There are plenty of plugins for jQuery such as:
Dynamic tooltip
Popup Bubble
jQuery Horizontal Tooltips
Coda Popup Bubble
Awesomeness
TipTip
(mb)Tooltip
vTip
jGrowl
jQuery Ajax Tooltip
Digg-style post sharing tool with jQuery
Input Floating Hint Box
Simpletip
qTip
Orbital Tooltip
And many more, check them here: Stylish jQuery Tooltip Plugins Webdesign
You can also just create your own using javascript. Add a mouseover event on the element then show a hidden div over the element with whichever html elements you want, in whichever color you need.
It is also more safe to use a javascript approach for cross-browser compatibility.

Categories