.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Gaurav Pal
Post New Web Links

WPF Rich Text Box Width size adjust to text?

Posted By:      Posted Date: December 04, 2010    Points: 0   Category :WPF

I am hoping to adjust the width of a custom watermarked rich textbox to match the length of the text. So, basically as you type the border area around the textbox grows also. (very similar to when you share a message on Windows Live messeenger). The only idea I can think of is have a custom converter to keep modifying the width on text change. In this apporach how do I measure the width of the text. Any suggestions how to make this easier or possible. Code snippets of XAML are shared below.

I am hoping to keep the textbox and small dropdown menu use auto and not size to content.


     <Style x:Key="UserRoleCommentBoxStyle" TargetType="{x:Type local:MyRichTextBox}">

            <Setter Property="SnapsToDevicePixels" Value="True" />

            <Setter Property="OverridesDefaultStyle" Value="True" />

            <Setter Property="AllowDrop" Value="True" />

            <Setter Property="Margin" Value="0" />

            <Setter Property="FontSize" Value="10px" />


View Complete Post

More Related Resource Links

Setting the size of the tab indent for a rich text box


I have a form with a rich text box on it. I have the "AcceptsTab" property set to true. What I would like to do now is set the size of the indent that is made when you press the tab key.

Does anyone know how to do this?


rich text editor



I need to implement one text editor in my application. I dont need a complex one, i just need a simple one.

please help me


Mission Impossible? Use Javascript to Disable a Multi-Line Rich Text Field


Hey Community,

Here's a tough one that I have struggled with and so far have not been able to find an answer for - how do you use Javascript to disable a multi-line rich text field.  I have customized a SP Edit form by adding a CEWP.  In the CEWP I have added the Javascript below (only a partial code sample provided) to disable several fields in the form.  The code works fine for single line text fields but it does not work for multi-line rich text fields.  Any suggestions?

<script language="javascript">
//This runs the function when the form first loads

//This locks the fields the users should not modify
function lockFields()
  var theInputTFTitle = getTagFromIdentifierAndTitle("Input","TextField","Title");
  theInputTFTitle.readOnly = true;
  theInputTFTitle.style.color = 'gray';
  //alert(" Value: " + theInputTFTitle.value);//for testing

   var theInputDDLReplyStatus = getTagFromIdentifierAndTitle("select","DropDownChoice","Reply Status");
  theInputDDLReplyStatus.disabled = true;
  //alert(" Value: " + theInputDDLReplyStatus.value);//for testing

  var theInpu

Javascript error on Rich Text Editor of CEWP

Hi all,

I have a problem that is really bugging and I wasn't able to find any workaround all day. I'll try to give as many details as possible:

I'm maintaining several site collections on a single server and this problem occurs only on one of the site collections. However it occurs on all subsites of this collection, it occurs on old pages and newly created pages, even on pages containing only one empty CEWP.

When I'm pressing the button for Rich Text Editor of CEWP I get the following error:

Message: Invalid argument.
Line: 5740
Char: 2
Code: 0
URI: http://www.dyrlaegeankenaevn.dk/_layouts/1030/HtmlEditor.js

I've tracked down the error with IE developer tools and I found that the error pops up in HtmlEditor.js at

function RTE2_GenerateLaunchArguments(parameterArray, webUrl, containerID)
    ............some code goes here......................
    ............some code goes here......................

I followed containerID down the stack and it comes from:

Rich text sql 2005

Hi I want rich text to be displayed on SSRS report in SQL 2005. That text is stored in database in html format from html editor textbox in frontend. Please help!! Thanks in Advance

getting the width of a text

a markup extension for getting the width from the number of characters in a text   public class TextWidthExtension : MarkupExtension { static TextWidthExtension() { try { var culture = CultureInfo.GetCultureInfo("en-us"); var font = Application.Current.TryFindResource("_Font") as FontFamily; var typeface = new Typeface(font, FontStyles.Normal, FontWeights.Normal, new FontStretch()); double fontsize = (double)Application.Current.TryFindResource("_FontSize"); double sum = 0; for (char c = ' '; c <= '~'; c++) { var formattedText = new FormattedText(c.ToString(), culture, FlowDirection.LeftToRight, typeface, fontsize, Brushes.Black); sum += formattedText.WidthIncludingTrailingWhitespace; } AverageWidth = (sum / ('~' - ' ')); typeface = new Typeface(font, FontStyles.Normal, FontWeights.Bold, new FontStretch()); sum = 0; for (char c = ' '; c <= '~'; c++) { var formattedText = new FormattedText(c.ToString(), culture, FlowDirection.LeftToRight, typeface, fontsize, Brushes.Black); sum += formattedText.WidthIncludingTrailingWhitespace; } AverageWidthBold = (sum / ('~' - ' ')); } catch { } }

Remove Word Style once copy and paste content to Rich text Editor in sharepoint 2010

Hi Guys, I have page layout for Users to add content for Page.I have site column for page content on field type HTML with Richtextmode="FUll Html". Now when user cut and paste content from Word document in this Field it carry word document style. how can i control this content on Page layout with CSS. Please adviseThanks Ron

Rich text field showing html code

I am an end user of Sharepoint. This issue only happens from my computer, not from any other within our organization. What happens is that when I edit an item in Sharepoint that contains a rich text field, HTML code is showing. Like so: <div class=ExternalClassC900CFF4F2BF4312A89133C01A6E3C96> Some text</div> This happens from any web browser. Sharepoint 2007 is used. I have Windows 7 x64. Any idea what is causing this?

Query Sharepoint list, rich text columns returning HTML tags

Hi! So I have an issue that maybe someone of you have encountered as well. I am querying a Sharepoint list and creating a report from the data collected from this list. This all works fine except that one of the columns in this list is of the type "Multiple lines of text" and also supports "rich text" with different fonts, sizes and so on. This has the effect that the text returned from this column is wrapped in HTML tags that specifies how the text should be formatted. Naturally I do not want this HTML code to appear in my report so for now I have used custom code to do a string.replace and replaced for example <div></div> and <br> with "". However, this column also has url references to documents and these links shows up like this "/servername/site/subsite/Gemensamma%20dokument/Mwh.docx">http://servername/site/subsite/Gemensamma%20dokument/Mwh.docx There is some sort of double reference to the document that I guess like the HTML tags are embedded in the answer from the rich text column and this is not so easy to do a string replace on because the url varies with the different document and document names. My question really is if anyone of you have done a similar report that I am doing, and have encountered this fenomen with this sharepoint column and how you did to solve this? I have tried to creat

How to modify Rich Text Editor Tool Bar

Besides using jQuery, is there an easy way to remove buttons such as 'Bold' and 'Italic' from the RTE tool bar? How about the buttons in the Rich Content Editor web part?

SharePoint 2010 Rich Text Editor field

I want to embed iframe tag in Sharepoint 2010 rich html text editor control, but it is simply remove the tags when i save the content. Please let me know how can i do this?

Rich Text in list forms & date picker

Hi, I was hoping that someone could help me on a few issues. I have created a custom list form in sharepoint designer to display the contents of my list in a nice format. I have also customised the edit form for the list. I am having a problem with special characters now showing up when they are being entered (the HTML does not seem to be parsed on the output). I would like to make a description field in my list edit form a rich text box, is this possible? This is the code I am using at the moment for the text box: <asp:TextBox runat="server" id="ff5{$Pos}" text="{@status}" textmode="multiline" __designer:bind="{ddwrt:DataBind('u',concat('ff5',$Pos),'Text','TextChanged','ID',ddwrt:EscapeDelims(string(@ID)),'@status')}" Width="600px" Height="100px" /> And this is the code that I am using on the display side of the list to show the status update: <xsl:value-of disable-output-escaping="yes" select="ddwrt:AutoNewLine(string(@status))" /> Is there code that I can use on the data entry side that will show a rich text box? Also then I will need to change the tag on the display end so it parses the HTML? In addition to this, is there specific code for a 'date picker' ? At the moment my date entry box is just a standard text box, is there code I can u

How to make bold/regular font text the same width

Hi! In Excel the width of texts in bold font cells have the same width as regular font ones. My question is how to do that programmatically (in a DataGridView, labels, paint event, anywhere...). I can do this if I draw the string twice in the paint event (1 pixel shift for the second draw), but it requires 2 drawings of course, which I think is not too efficient. Is there any other solution? Some trick in creating the bold font? Thank you, Feri

RDLC reports with Rich text support

Hi, I am looking for the solution to display the Rich text in RDLC file with local processing mode. I have read from the following link which stated that Microsoft made this feature available in Visual Studio 2010. http://blogs.msdn.com/b/brianhartman/archive/2010/04/20/visual-studio-2010-is-now-available.aspx Can anyone please tell me how to use this? Thanks in Advance!!! Best Regards, Subalakshmi Vijayarajan.

SSRS BUG? When a FontStyle expression is used in a report, the Browser Text Size setting overrides t

I have created a report that has the same font size for all the sections in the report. Some sections' fields use a FontStyle expression that changes the FontStyle between Normal and Italics conditionally. I run the report through the reportserver interface and the report looks fine. I run the report through the ReportViewer control and the the fields which use the FontStyle formula are overridden by the Browser's Page Text Size. Also, when I look at the inline HTML Style that's generated, the fields with the formula don't have a style, they are blank, while the fields with without a FontStyle expression have an inline HTML Style generated. And this is probably why the browser text size setting can override. This seems like a ReportViewer HTML render bug... Or is there a way around it??

Changing font size for all text in DataView webpart?

I'm in SharePoint designer. Would you know what class I need to change the font tag on to impact the size of font for the entire dataview? I've tried the DataFormwebpart, the webzone, the table. No luck. And when I change the ms-vh or ms-vb it only changes it it on the tr or td selected. I'm also not seeing an option inside the webpart properties. <table border="0" width="100%" cellpadding="2" cellspacing="0" style="font-size: large"> Thanks.  

how to print rich textBox Formatted text

Hi,  I have some text in rich text box format in a table.The data is like  {\rtf1\ansi\ansicpg1252\deff0\deflang16393{\fonttbl{\f0\fnil\fcharset0 NSimSun;}{\f1\fnil\fcharset0 Microsoft Tai Le;}{\f2\fnil\fcharset0 MingLiU_HKSCS;}{\f3\fnil\fcharset0 Palace Script MT;}{\f4\fnil\fcharset0 Microsoft Sans Serif;}} {\colortbl ;\red0\green192\blue0;} \viewkind4\uc1\pard\cf1\b\f0\fs44 hello hi\par \lang1033\f1 hi i am fine\par \f2 about u?\lang16393\b0\i\f3\par \par \par \cf0\i0\f4\fs17\par }  Now,I want to print the data in corresponding format.can u please Help me.....
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend