Silverlight RichtextBox Xaml Property, cannot set value (exception) - c#

Hi I want to set the Xaml property of my silverlight richtext box.
this.Dispatcher.BeginInvoke(() =>
{
richTextBox1.Xaml = "<Paragraph>Blah</Paragraph>";
});
However I get the following exception..
System.ArgumentException: value
at System.Windows.Controls.RichTextBox.set_Xaml(String value)
Can anybody explain this ?
Maybe I am not in the

You actually want to add an XML namespace to the string, so that the Paragraph object can be resolved. Like:
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
As you really only want a single xmlns entry, surround it with a Section block. Your complete working string will be this:
richTextBox1.Xaml = "<Section xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\"><Paragraph>Blah</Paragraph></Section>";
To work this out, I entered text into a RichTextBox (e.g. "Blah") and then viewed the textbox1.Xaml property (always investigate using working methods first to see what comes out of it).

Related

How to make USS properties work in custom variables?

I tried to make a USS variable as following:
.ds-node__text
{
background-color:#FF0000;
align-content:stretch;
}
and apply it to a label by
Laabel label = new Label()
{
text = Name
};
titleContainer.AddToClassList("ds-node__text");
titleContainer.Insert(0, label);
But the style did not applied to it.
When I change .ds-node__text. to Label, it works fine but applied to "all labels".
I went on Google and see if USS variables are applied differently, I see in the official document that it uses background instead.
But when I try it, the console told me Unknown property 'background' (did you mean 'background-color'?).
If I add > .unity-label after the variable name, it will work but add an extra empty label after the assigned label, which I don't know how to get rid of:
Why!? Where did I do wrong?
Thank you very much for your help.
I had tried:
background from USS Custom Properties
-unity-background-image-tint-color from USS Property Reference
What I'm expecting to resolve:
Successfully apply style with the variable.

How to avoid C# adding an escape character when obtaining string value from asp.net resource file

I am trying to pass a Unicode character corresponding to fontawesome icons to the text property of an asp.net web forms button control from the code behind. It works fine when I do the following:
button1.Text = "\xf044";
However I have to get it from a resource file to conform with the company requirement. When I set the resx file with name/value as "Edit" and "\xf044". The problem is that when I set the Text property equal to this value from resx, it is set automatically as follows.
button1.Text = "\\xf044";
Is there anyway to avoid this? I tried something as follows
button1.Text = myResx.Edit.Substring(1);
Now the button instead of displaying the corresponding font icon, simply displays "\xf044".
Thanks

Mono.TextEditor highlight line

I am making a pascal code editor in Mono in MonoDevelop. I am using Mono.TextEditor as a code editor widget. However, I cannot find how to highlight a line in the widget.
After compilation, I collect line numbers where errors occur, and so I want to highlight them in red. I found
Mono.TextEditor.LineBackgroundMarker
which seems to relate to what I want to do, but I cannot find where and how to use it.
Another option I was looking into was ViBuilder, but I don't even know how to use that. I can think of two ways to solve this problem:
Simply make highlight
Mark a line as error, as default style includes:
{ "name": "Underline(Error)", "color":"invalid-red" }
which also seems to be a possible solution.
You can highlight lines in the text editor by adding markers to the underlying document. Use the TextDocument.AddMarker method, as follows:
TextEditor textEditor;
var marker = new Mono.TextEditor.LineBackgroundMarker();
int lineNumber = ...;
textEditor.Document.AddMarker(lineNumber, marker);
textEditor.QueueDraw();
Also have a look at the Mono.TextEditor.StyleTextMarker class. This class has already the properties "BackgroundColor" / "Color" that you are looking for. Underlining may have to be done manually (for example by inheriting from StyleTextMarker and overriding the Draw method).

What is code equivalent of XAML to preserve whitespace?

What is c# code equivalent of following XAML, where I have a RichTextBox and I have selected Paragraph, and I want to enable/disable white space on this paragraph. In XAML I know how to enable, but I need to do this in code.
<Paragraph xml:space=\"preserve\"> Tabbed Code</Paragraph>
There is an equivalent I have found and its here,
void EnableWhiteSpace(Paragraph p, bool enable = true){
if(enable){
System.Windows.Markup.XmlAttributeProperties
.SetXmlSpace(this.Document, "preserve");
}
else{
System.Windows.Markup.XmlAttributeProperties
.SetXmlSpace(this.Document, "default");
}
}
This is still not working !!! I am not getting tabs !!...
Here is my problem, I have a RichTextBox which is used to edit code and which does syntax highlighting. Everything is fine except when I call following I see no tabs in my code.
TextRange tr = new TextRange(
myRichTextBox.Document.ContentStart,
myRichTextBox.Document.ContentEnd);
string text = tr.Text;
The text that I receive contains no tabs, so I thought enabling whitespace on every paragraph before doing text range might give me tabs.
UPDATE
I tried navigating every inlines (run) in the paragraph, none contains tab, I am just loosing all the tabs :(
There is no equivalent. The XML option xml:space="preserve" is valid only for interpreting XML files (in your case, XAML, which is a kind of XML), and has no meaning in C# as there are no XML files involved.
The C# equivalent of your XAML code would be following:
Paragraph p = new Paragraph();
p.Inlines.Add(new Run(" Tabbed Code"));
RichTextBox is buggy, it will just ignore all tabs, however its problem of WPF itself and cant be fixed without doing complex workarounds.
Alernative is to write your own FlowDocument to text converter, however this is very complex as nodes do not directly give any line or tag information.

how to get text attribute from a asp:panel

Probably a simple question, but I've been browsing now for 30 mins and STILL cant find a solution!
i have a panel and it has an attribute text="something". but the panel class does not seem to have a getAttribute method... Which personally, I think is STUPID!
Code follows:
foreach (Control c in clientGrid.Controls)
{
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.Panel"))
{
/*Something*/ textInsidePanel = ((Panel)c)./*Somthing*/
}
}
Now i've tried AttributeCollection text = ((Panel)c).Attributes;
and
string text = ((Panel)c).Attributes.toString();
and other useless things...
This should be really simple! when i inspect element on chrome, I can see the panel, (well the div) and i can see the text attribute right there. and i can see its value! but i want my c# code to have the value to!!
Please Help!
Alex
if I get you question right - you can use next code
asp part
<asp:Panel runat="server" ID="pnl" Text="hello world"></asp:Panel>
c# part -
string s = pnl.Attributes["Text"];
Have you tried using an accessor?:
string val = YourPanel.Attributes["Text"];
// ^ that's your attribute name
That should get the attribute's value BUT I'm pretty sure what you are doing isn't possible as attribute values are not persisted between postbacks (at least not when set via a client script). To do that you should use hidden inputs or some other form element.
The Panel control itself doesn't have a text property. But if you access the inner text as a LiteralControl it will work:
var panelContent = ((Panel)c).Controls[0] as LiteralControl;
var text = panelContent.Text;

Categories

Resources