Showing html text in FlowDocumentReader - html

I have a FlowDocumentReader control in my application.
<FlowDocumentReader Document="{Binding FlowDocument}" Style="{DynamicResource FlowDocumentStyle}" />
And here's how I set the text to the FlowDocumentReader:
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add("some <b>book</b>");
FlowDocument.Blocks.Add(paragraph);
The problem is that 'book' isn't shown like html, the tags are visible in the wpf application.
I tried using this converter:
http://code.msdn.microsoft.com/windowsdesktop/XAML-to-HTML-Conversion-ed25a674/view/SourceCode
but then the text shown in my wpf application looks like this:
<FlowDocument xml:space="preserve" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"><Paragraph>some <Run FontWeight="bold">book</Run></Paragraph></FlowDocument>
and again it's not bold. How can I do this?

Use UI Elements to show formatted text and them to InlineUIContainer of Paragraph.
Paragraph paragraph = new Paragraph();
paragraph.Inlines.Add("some");
Label lb = new Label();
lb.FontWeight = FontWeights.Bold;
lb.Content = " Book";
paragraph.Inlines.Add(new InlineUIContainer(lb));
this.Doc.Document = new FlowDocument();
this.Doc.Document.Blocks.Add(paragraph);

Related

How to set qlabel text's opacity in PyQt?

I have a label and I want to set it html\css formatted text from text variable.
label = QtGui.QLabel()
text = '''<font face="tahoma" color="#45688E">THIS TEXT</font>'''
label.setText(text)
I need the word THIS to be colored with my color(#45688E) and word TEXT to be transparent.
The idea is that I want label to show only one word on screen, meanwhile I could programatically get two words.
How to do it?
Thank you.
Update1: photo
Code:
from PyQt4 import QtGui, QtCore
import sys
app = QtGui.QApplication(sys.argv)
window = QtGui.QWidget()
window.resize(300, 400)
window.setWindowTitle('TITLE1')
window_layout = QtGui.QVBoxLayout()
window.setLayout(window_layout)
label = QtGui.QLabel()
text = '''<font face="tahoma"><span style="color:#45688E">THIS</span><span style="opacity:0"> TEXTANOTHER_WORD</span></font>'''
label.setText(text)
window_layout.addWidget(label)
window.show()
sys.exit(app.exec_())
Wrap your first word in a span tag and style with a color. Add all other words in another span tag and set the opacity of the span tag to 0
'''<font face="tahoma"><span style="color:#45688E">THIS</span><span style="opacity:0">TEXTANOTHER_WORD</span></font>'''
Browser Snippet below
<font face="tahoma"><span style="color:#45688E">THIS</span><span style="opacity:0">TEXTANOTHER_WORD</span></font>
EDIT:
Solution 2
'''<font face="tahoma"><span style="color:#45688E">THIS</span><span style="display:none">TEXTANOTHER_WORD</span></font>'''
A somewhat odd solution with PyQT
Somewhat setting the color to transparent hides that text
style="color:transparent"
Example
text = '''<font face="tahoma" color="red" style="color:green;"><span>THIS</span><span style="color:transparent">TEXT</span></font>'''
Picture below

Multiline Radiobutton

I've radio buttuons in my WP-8 application.
All contents of my radiobuttons are overlapping. I've fixed height and width but words are not wrapping to second line. How can I solve this problem?
Please do not say something like "\n" content is dynamic.
You are probably setting text to Content property as a string. But you can also use TextBlock.
XAML
<RadioButton>
<TextBlock Text="This is very long text that I want to wrap. Is it long enough?"
TextWrapping="Wrap"/>
</RadioButton>
C#
RadioButton rb = new RadioButton();
rb.Content = new TextBlock()
{
Text = "This is very long text that I want to wrap. Is it long enough?",
TextWrapping = TextWrapping.Wrap,
};
Result

img tag is not working properly in actionscript3 TextField

I have a TextField.
Here is a snippet:
this.textField = new TextField();
this.textField.defaultTextFormat = font.format;
this.textField.selectable = true;
this.textField.border = true;
this.textField.wordWrap = true;
this.textField.multiline = true;
And here is the method to add new line to the textField box:
this.textField.htmlText = 'some text <IMG SRC="http://gravitatestudio.com/wp-content/themes/gravitate/images/facebook.png">';
The issue is that an image is always placed UNDER text instead of the END OF THE TEXT.
Here is the trace(this.textField.htmlText) after html text has been added:
<P ALIGN="LEFT"><FONT FACE="Verdana" SIZE="12" COLOR="#FFFFFF" LETTERSPACING="0" KERNING="0">some text <FONT SIZE="2"><IMG SRC="http://gravitatestudio.com/wp-content/themes/gravitate/images/facebook.png"> </FONT></FONT></P>
Also I need to add an image to any side of the text like a chat message using smiles (left, middle, right side of the text).
Any suggestions?
TextField html text is very limited and thats why Adobe released TLFTextFields which will give you much more control over the layout of elements in the field. I have personally used it and have made entire chats out of one textfield with images, links etc.
resource:
adobe: http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/fl/text/TLFTextField.html
tutorial:
http://flashsimulations.com/2010/09/10/handling-image-loading-in-tlf-textflow-and-textfield/

How to convert Html text into normal plain text?

I have html text which is coming from backend and i need to convert it into normal text to show up in TextArea.
Is there any way to convert Html text into normal plaintext by usingFlex framework`?
You will have to use Regexp to remove tags.
From here:
var myString:String = "<p><b>bold</b> <i>italic</i> <a href='#'>link</a> <br>linebreak</p>";
trace(myString)
var removeHtmlRegExp:RegExp = new RegExp("<[^<]+?>", "gi");
myString = myString.replace(removeHtmlRegExp, "");
trace(myString);
// OUTPUT
// <p><b>bold</b> <i>italic</i> <a href='#'>link</a> <br>linebreak</p>
// bold italic link linebreak
In case I got you wrong and you want to display HTML tags in textarea, use escape() function

how to use text tag in MVC 3 razor

i want to use regex on the views i have in MVC 3 page. how i can use
when i wrap them with text tag they not work ex:
<text> var pattern = #fjkfdkl</text>
i not want to put ## instead of # on every pattern. well what is the way and rule for using text tag in MVC
When you wrap something in a text tag your are saying to Razor that "this is text" not code. If you want code you can then do a code block like:
<text>#{ var pattern = fjkfdkl; }</text>
If you are doing this in some sort of loop you can just continue writing your code:
foreach(var o in listOfObjects) {
var pattern = fjkfdkl;
}
In the above example razor knows whats code and what is not. You can then expand on the above example if you want to put markup in the loop:
foreach(var o in listOfObjects) {
var pattern = fjkfdkl;
<text>
Hello World!
</text>
}
or
foreach(var o in listOfObjects) {
var pattern = fjkfdkl;
<p>
Hello World.
<p>
}
You only really need to use the <text></text> tags inside of loops where you don't have any html tags.
Razor is smart enough so when you open your tag inside a loop e.g. <p> it know until that tag is closed then its in markup. When it is closed it will then look for a } for the closing of a loop (or another html tag).