Thursday, May 26, 2022 ..:: ::.. Register  Login
 Bloggers Minimize

 Sponsors Minimize

 Users Online Minimize
Membership Membership:
Latest New User Latest: HarrisSampso
New Today New Today: 10
New Yesterday New Yesterday: 6
User Count Overall: 9826

People Online People Online:
Visitors Visitors: 18
Members Members: 0
Total Total: 18

Online Now Online Now:

 Welcome to! Minimize

If you are a developer or designer who is creating cutting edge user interface experiences using Microsoft Expression Blend you've just found a great resource!  The purpose of this site is to share our experience with this brand new product.  As with any new piece of software there is a ton to discover.  Bugs will be revealed and workarounds discovered, hopefully this can be a resource to share in the discovery process!

While this site will focus largely on Expression Blend, it will also encompass WPF, Visual Studio, Silverlight, and other .net 3.5 technologies as they relate to the creation of great software.

Please login using your Microsoft LiveID or register a new account.  Doing so will let you comment on any of the blog entries on the site.  We look forward to helping you in your endeavors as well as you helping others in theirs!  We'd love to have more bloggers on our site...if you are interested please register and contact us!

Follow us:

 WPF RichTextBox may offer impressive features, but seems to lack features readily available from prior RichEdit-based RichTextBox Minimize
Location: BlogsRob Tuch    
Posted by: RobTuch 1/8/2008 1:54 PM



I was excited at the prospect of building an editor around the new WPF RichTextBox, which Microsoft lists as the functional equivalent of the WinForms RichTextBox (see  This RichTextBox  should finally permit insertion of dazzling media elements and flexible layouts...


However, there are some implementation snags.  For example, many of the formatting functions that were previously available by a simple call to a (WinForms) RichEdit-based RichTextBox property, now require implmentation of an equivalent property.  For example a SelColor property that changes the text color:


        Public Property SelColor() As Color

            Dim oCurrentColor As SolidColorBrush


                ' Get current foreground text color


                    oCurrentColor = WPFRichTextBox.Selection.GetPropertyValue(Inline.ForegroundProperty)


                    oCurrentColor = WPFRichTextBox.Foreground

                End Try

                SelColor = oCurrentColor.Color

            End Get

            Set(ByVal value As Color)

                ' Get current fore color and convert to System.Drawing.Color

                WPFRichTextBox.Selection.ApplyPropertyValue(Inline.ForegroundProperty, New SolidColorBrush(Color.FromRgb(value.R, value.G, value.B)))

            End Set

        End Property


This is a relatively simple property to implement, but others require further code for error and text context checking.


Also, although the WPF RichTextBox supports RTF text, it seems to be a subset of that supported by the RichEdit-based RichTextBox.  For example the \protect (for protected text) and \v (for hidden text) are ignored.  There are some workarounds for this (for example on could uniquely color-code the protected text and use a practically-invisible fontsize for the hidden text), but these require additional event handlers (to prevent edit when cursor is on protected text, to skip over the "invisible" characters, and convert the XAML to/from corrected RTF as needed).  It would be great to learn that these standard RichEdit RTF features will just be available in future version of the WPF RichTextBox.


In addition, although Spell-checking is available as a built-in feature, it is currently limited to Western languages, without support for custom dictionaries.  It has been suggested that Microsoft will allow for custom dictionaries and expanded language support in the (hopefull very) near future.


The WPF RichTextBox poses a another challenge in that the underlying XAML of selected content is not readily availalable with all content intact--any UI elements added are converted to a textual equivalent (e.g., <InlineUIContainer>..</InlineUIContainer> elements that contain UI elements convert to a <run></run>).  This poses a difficulty when one expects to support drag/drop or cut/paste with the enhanced UI elements as well as text.  So far, a workaround has been to handle the drag/drop (via WPFRichTextBox_PreviewMouseMove and WPFRichTextBox_PreviewDrop events respectively) or cut/paste operations (via WPFRichTextBox_PreviewKeyDown event) so that any replaced UI elements can be restored to the original content prior to completion of the Drop or Paste.  For now, it seems this can be accompished using the XAMLWriter with code similar to the following...

    Private Function GetTextRangeXAML(ByVal objTextRange As TextRange) As String
        ' Traverse elements convered by current range and construct XAML

        Dim objParagraph As Paragraph
        Dim objTextElement As TextElement
        Dim objInline As Inline
        Dim strXAML As String
        Dim strSectionStart As String
        Dim objSection As New Section
        Dim booStart As Boolean
        Dim objSelectionText As String
        Dim objTR As TextRange

        ' Get paragraph of start position
        objParagraph = objTextRange.Start.Paragraph
        booStart = True

        objTextElement = objTextRange.Start.Parent
        If objTextElement.GetType.Name = "Paragraph" Then
            ' Started at paragraph, so set 1st Inline to 1st Inline of Paragraph
            objInline = objParagraph.Inlines.FirstInline
            objInline = objTextElement
        End If

        Do While Not objParagraph Is Nothing
            strXAML = strXAML & "<Paragraph>"
            ' handle inline elements within the paragraph
            Do While Not objInline Is Nothing
                Dim objMemoryStream As New MemoryStream()
                Dim objStreamReader As New StreamReader(objMemoryStream)
                Select Case objInline.GetType.Name
                    Case "Run"
                        If booStart Then
                            ' Get content in run offset from start position
                            booStart = False
                            objTR = New TextRange(objTextRange.Start, objInline.ElementEnd)
                            objTR.Save(objMemoryStream, DataFormats.Xaml)
                            objMemoryStream.Position = 0
                            objSelectionText = objStreamReader.ReadToEnd()
                            'objSelectionText = "<Run>" & objTR.Text & "</Run>"
                            strXAML = strXAML & objSelectionText
                            ' Get full run xaml
                            objTR = New TextRange(objInline.ElementStart, objInline.ElementEnd)
                            objTR.Save(objMemoryStream, DataFormats.Xaml)
                            objMemoryStream.Position = 0
                            objSelectionText = objStreamReader.ReadToEnd()
                            'objSelectionText = "<Run>" & objTR.Text & "</Run>"
                            strXAML = strXAML & objSelectionText
                        End If
                    Case "InlineUIContainer"
                        ' Get XAML for object
                        strXAML = strXAML & XamlWriter.Save(objInline)
                    Case Else
                End Select
                objInline = objInline.NextInline
            ' Next paragraph
            strXAML = strXAML & "</Paragraph>"
            objParagraph = objParagraph.NextBlock
            If Not objParagraph Is Nothing Then
                objInline = objParagraph.Inlines.FirstInline
            End If

        strSectionStart = XamlWriter.Save(objSection)
        strSectionStart = strSectionStart.Substring(0, strSectionStart.IndexOf("/>")) & ">"
        strXAML = strSectionStart & strXAML & "</Section>"

        Return strXAML
    End Function

Permalink |  Trackback

Comments (5)   Add Comment
Re: WPF RichTextBox may offer impressive features, but seems to lack features readily available from prior RichEdit-based RichTextBox    By freddy on 12/18/2008 12:23 PM

Re: WPF RichTextBox may offer impressive features, but seems to lack features readily available from prior RichEdit-based RichTextBox    By Simon on 2/23/2009 7:40 AM
Like most of WPF it has taken something simple, elegant and easy to use and replaced it with something half baked, difficult, confusing and in need of 10 times as much code as before.<br><br>WPF is a joke

Re: WPF RichTextBox may offer impressive features, but seems to lack features readily available from prior RichEdit-based RichTextBox    By wd on 12/29/2009 2:13 AM
The English author,<a href="" title="The Wars">The Wars</a> Richard Savage, was<a href="" title="web games">web games</a> once living inLondon<a href="" title="free web game">free web game</a> in great poverty.<a href="" title="online web game">online web game</a> In order to<a href="" title="web game">web game</a> earn a little<a href="" title="free web games">free web games</a> money he hadwritten <a href="" title="web gaming">web gaming</a>the story of<a href="" title="web online games">web online games</a> his life, but <a href="" title="on web games">on web games</a>not many copies<a href="" title="free online web games">free online web games</a> of the bookhad<a href="" title="play web games">play web games</a> been sold in<a href="" title="new games on the web">new games on the web</a> the shops, and<a href="" title="play free web games">play free web games</a> Savage was living <a href="" title="game web site">game web site</a>from hand tomouth. <a href="" title="web game sites">web game sites</a>As a result<a href="" title="on the web games">on the web games</a> of his lack<a href="" title="web games online free">web games online free</a> of food he became very ill.<br>    By coach outlet store online on 5/2/2014 2:59 AM
your wedding <a href="" title="true religion outlet">true religion outlet</a>'t just one of the <a href="" title="">coach factory outlet</a> days of your <a href="" title="Louis Vuitton bags">louis vuitton handbags</a> - it's also one of <a href="" title="coach outlet">coach outlet</a> longest. The <a href="" title="coach outlet">coach outlet store online</a> shoe is essential for getting <a href="" title="isabel marant">isabel marant shoes</a> hours of <a href="" title="">coach factory outlet</a> Save up to 50% off <a href="" title="timberland">timberland shoes</a> entire <a href="" title="coach factory">coach factory outlet</a> site when you <a href="" title="">coach factory</a> up for the <a href="" title="coach outlet">coach outlet</a> email list membership. (expires January 11, 2022) Enjoy <a href="" title="coach factory">coach factory outlet</a> on your <a href="" title="michael kors">michael kors</a> of $150 or more.<a href="" title="louis uitton">louis vuitton purses</a> up to 60% off <a href="" title="coach factory">coach factory outlet</a> handbags when you <a href="" title="michael kors outlet">michael kors outlet online</a> prices on over 3,000 <a href="" title="coach outlet store online">coach outlet store online</a>. Hoochie mama! <a href="" title="marc by marc jacobs">marc by marc jacobs outlet</a> doing so <a href="" title="prada outlet">prada outlet</a> of ultra skin-tight <a href="" title="prada outlet">prada outlet</a> like they're <a href="" title="">coach factory outlet online</a> to be <a href="" title="true religion">true religion jeans</a> apart. <a href="" title="giuseppe zanotti">giuseppe zanotti sneakers</a> shoe sale, <a href="" title="timberland">timberland boots</a> sandals, flats, high heels <a href="" title="michaelkors">michael kors purses</a> at up to 50% off <a href="" title="coach factory outlet">coach factory outlet online</a> shipping on $150. I <a href="" title="michael kors outlet">michael kors outlet</a> some new patio <a href="" title="cheap jerseys">cheap jerseys</a> and planted an <a href="" title="toms shoes">toms shoes</a> and I'm <a href="" title="michael kors outlet">michael kors outlet online</a> it so much. yes <a href="" title="">coach factory outlet</a> is required. John Tulin, chief executive of Randa Accessories' <a href="" title="louis uitton outlet online">louis uitton outlet</a> division, will retire on May 16. Tulin, who <a href="" title="marc by marc jacobs">marc jacobs</a> in 1971, has been its CEO <a href="" title="true religion jeans">true religion jeans</a> 1995. <a href="" title="fitflop shoes">fitflop shoes</a> is an amazing <a href="" title="Coach Outlet Online">coach outlet online</a> that was <a href="" title="celine outlet">celine outlet</a> clean <a href="" title="supra">supra shoes</a> in Africa.<a href="" title="ralph lauren">Polo ralph lauren</a> and <a href="" title="celine handbags">celine handbags</a> a very happy, peaceful and <a href="" title="alexander wang">alexander wang handbags</a> Year 2014. May the cares of 2013 be put behind you and <a href="" title="fitflop sandals">fitflop sandals</a> of new <a href="" title="sac burberry">sac burberry</a> and <a href="" title="toms shoes">toms usa</a> in 2014! <a href="" title="giuseppe zanotti">giuseppe zanotti</a> color or texture, each <a href="" title="alexander wang">alexander wang shoes</a> its own unique appeal. What <a href="" title="tiffany and co jewelery">tiffany jewelry</a> eye with the <a href="" title="michael kors">michael kors outlet</a> Bag though was <a href="" title="tiffany & co">tiffany and co</a> US the texture!    By coach outlet online on 1/17/2015 1:47 AM
hello!<br></p><br><p>measurements <a href=""><strong>coach factory outlet 70% off -coach outlet</strong></a> bags are <a href=""><strong>coach factory outlet : $39 new 2015 coach outlet bags</strong></a> large though often carried by hand, the lines do not <a href=""><strong>coach outlet online - 75% off coach purses outlet</strong></a> have middle <a href=""><strong>coach factory online - shop the latest designer bags</strong></a> ground, <a href=""><strong>coach factory outlet - coach outlet 80% discount</strong></a> modern, <a href=""><strong>coach outlet - coach factory outlet chesterfield mo</strong></a> square or <a href=""><strong>coach factory outlet - coach outlet 80% up clearance</strong></a> round and <a href=""><strong>coach outlet online - coach handbags</strong></a> feminine. the <a href=""><strong>coach factory outlet - coach outlet, Inc. - official site</strong></a> bags are carried by hand or <a href=""><strong>coach outlet - coach outlet stores online</strong></a> under your arm, point <a href=""><strong>tiffany and co - does tiffany have an outlet</strong></a> out that <a href=""><strong>birkin hermes bag -hermes bag</strong></a> even the <a href=""><strong>coco chanel handbags - coco chanel outlet- chanel bags</strong></a> clutch, <a href=""><strong>hermes belts - hermes belts for 70% off handbags outlet</strong></a> except for the <a href=""><strong>coach factory outlet - coach outlet sale 70% off</strong></a> small jeweled versions, lengthen the <a href=""><strong>coach outlet store online - authentic coach factory stores</strong></a> flat but at <a href=""><strong>coach outlet - official coach factory outlet</strong></a> the <a href=""><strong>coach outlet - coach factory outlet $150+ orders</strong></a> same time <a href=""><strong>coach outlet store online - coach factory outlet discount 39.99</strong></a> almost spacious. <a href=""><strong>coach factory outlet - local results for coach outlet</strong></a> clutches, modern <a href=""><strong>coach outlet store online - 20% coach factory outlet stores</strong></a> backpacks, <a href=""><strong>kate spade outlet online - kate spade jewelry outlet</strong></a> totes: this <a href=""><strong>coach factory outlet store 80% discount</strong></a> about a <a href=""><strong>kate spade handbags - kate spade new york crossbod</strong></a> accessory. here, <a href=""><strong>valentino shoes</strong></a> all the <a href=""><strong>pas cher sac chanel 2015</strong></a> best, <a href=""><strong>kate spade outlet - kate spade clearance</strong></a> busiest <a href=""><strong>coach factory outlet - store online</strong></a> bags we <a href=""><strong>the north face outlet store online</strong></a> want to grab onto. <br></p><br>despite facing <a href=""><strong>kate spade outlet - official kate spade outlet online</strong></a> colder than <a href=""><strong>michael kors outlet - michael kors stores - sale</strong></a> mars, the reality tv starlet was showing all kinds of leg as this thursday. clad in a skin-tight pencil skirt, <a href=""><strong>michael kors outlet online- factory outlet michael kors</strong></a> leather jacket <a href=""><strong>michael kors outlet - michael kors - official site</strong></a> and stiletto <a href=""><strong>louis vuitton outlet stores - Images of louis vuitton</strong></a> heels, <a href=""><strong>chanel handbags - chanel bags - chanel outlet store</strong></a> kardashian <a href=""><strong>michael kors outlet - michael kors on sale</strong></a> any of it from <a href=""><strong>michael kors outlet - shop for michael kors outlet online</strong></a> and her cold <a href=""><strong>chanel black friday - fragrance and beauty</strong></a> as she grabbed lunch with pal jonathan <a href=""><strong>michael kors outlet - michael kors handbags</strong></a> in <a href=""><strong>michael kors outlet online sale- michael kors</strong></a> with pride! <a href=""><strong>michael kors outlet store- cheap sale 78% off online</strong></a> most powerful <a href=""><strong>burberry outlet online</strong></a> color makes for a <a href=""><strong>michael kors outlet online - michael kors</strong></a> your new year, and it <a href=""><strong>louis vuitton - louis vuitton outlet</strong></a> also makes for the <a href=""><strong>michael kors outlet - michael kors outlet online sale</strong></a> perfect <a href=""><strong>louis vuitton - store locator</strong></a> this <a href=""><strong>louis vuitton outlet - louis vuitton - official site</strong></a> pale grays and <a href=""><strong>louis vuitton outlet - louis vuitton red carpet fashion louis vuitton bags</strong></a> neutrals.january I buy <a href=""><strong>chanel outlet - chanel outlet online - sacs a main chanel</strong></a> sales.<br> we <a href=""><strong>giuseppe Zanotti shoes</strong></a> may want <a href=""><strong>red bottom shoes - red bottom shoe 70% off - designer red bottom shoes</strong></a> new bag that hits the <a href=""><strong>toms shoes outlet online - toms shoes outlet online free shipping - toms shoes</strong></a> market, but the fact of the matter is that we couldn't (<a href=""><strong>michael kors outlet store - save 40 - 70%. all the sales</strong></a>) actually <a href=""><strong>louis vuitton handbags - louis vuitton outlet - louis vuitton outlet online</strong></a> single one. <a href=""><strong>louis vuitton outlet online - louis vuitton official usa website</strong></a> It's all about picking and choosing. <a href=""><strong>prada factory outlet store - prada handbags</strong></a> while the <a href=""><strong>north face outlet - the north face jacket</strong></a> trendy piece is a justified <a href=""><strong>true religion jeans - true religion brand jeans</strong></a>, what you really want to <a href=""><strong>burberry handbags - outlet at prices up to 70% off. shop nordstrom rack online</strong></a> in are the <a href=""><strong>sac chanel sacs a main pas cher 2015 chanel site officiel</strong></a> classics.<br> <p><br>I received not <a href=""><strong>valentino - valentino's restaurant baltimore - valentino shoes</strong></a> one,<a href=""><strong>oakley sunglasses - oakley sunglasses oil rig -oakley official site</strong></a> but two <a href=""><strong>prada handbags - prada outlet online store</strong></a> monogrammed <a href=""><strong>prada handbags - discount prada outlet sale</strong></a> for christmas. yes, I am more <a href=""><strong>polo ralph lauren - ralph lauren 30% coupon code - polo ralph lauren outlet online</strong></a> a little obsessed. but I've <a href=""><strong>celine handbags - celine handbags nordstrom</strong></a> say-I don't think I'm alone. since I started carrying my cuyana <a href=""><strong>marc by marc jacobs - marc jacobs handbags on sale</strong></a> tote, I've <a href=""><strong>oakley vault - oakley holbrook frogskins black friday</strong></a> four <a href=""><strong>ralph lauren outlet - ralph lauren outlet mall online</strong></a> from complete strangers, <a href=""><strong>ray ban sunglasses - ray ban sunglasses sunglass hut - ray ban sunglasses cockpit</strong></a> which pretty much never <a href=""><strong>ray-ban sunglasses - ray ban 3362 sunglasses</strong></a> to me.<br> I need to <a href=""><strong>celine handbags - celine handbags barney's</strong></a> stop myself <a href=""><strong>ray ban sunglasses - ray ban aviator sunglasses - ray ban clubmaster sunglasses</strong></a> so <a href=""><strong>true religion outlet - official true religion outlet</strong></a> much tat, but the <a href=""><strong>polo ralph lauren outlet online - polo ralph lauren official site</strong></a> of a good discount is <a href=""><strong>ray ban outlet store online - ray ban outlet</strong></a> much for me. I <a href=""><strong>ray ban sunglasses - ray-ban is a brand of sunglasses</strong></a> buy <a href=""><strong>red bottom shoes free shipping + free exchanges. shoes and bags as low as $39.95!</strong></a> stuff that's not my size or my colour, <a href=""><strong>nike air jordan - nike air jordan release dates - nike air jordan retro 13</strong></a> and often <a href=""><strong>tory burch shoes - tory burch handbags sale</strong></a> buy <a href=""><strong>tiffany and co - tiffany diamond necklaces outlet</strong></a> stuff <a href=""><strong>hollister clothing store - hollister clothing for sale - hollister store online</strong></a> because it's cheap. I need a <a href=""><strong>toms shoes outlet online - toms shoes on sale 80% off</strong></a> shopping <a href=""><strong>true religion outlet - cheap true religion jeans wholesale</strong></a> detox. <a href=""><strong>oakley sunglasses - cheap oakley sunglasses $9 only</strong></a> any tips? <a href=""><strong>oakley sunglasses - military oakley sunglasses - wholesale discount oakley sunglasses</strong></a> turns <a href=""><strong>tory burch outlet - tory burch handbags 80% off</strong></a> the <a href=""><strong>abercrombie and fitch - abercrombie 30% off coupon - abercrombie outlet sale</strong></a> traditional <a href=""><strong>oakley sunglasses - us standard oakley government sales</strong></a> concept <a href=""><strong>frey wille jewellery - frey wille - frey wille usa</strong></a> upside <a href=""><strong>abercrombie black friday - abercrombie and fitch sale</strong></a> down by starting at <a href=""><strong>sac longchamp - sac chanel pas cher</strong></a> high <a href=""><strong>timberland shoes - timberland boots on sale</strong></a> price and working backwards. first, sign up for a <a href=""><strong>abercrombie and fitch - abercrombie and fitch coupons discounts</strong></a> account, <a href=""><strong>true religion - official true religion outlet</strong></a> and then let the fun begin!<br>

Your name:
Add Comment   Cancel 

 Search Minimize

 Archive Minimize

 Blendblog Survey Minimize
Our next client application will be written using:

Which Tablet Do you expect to buy?

Submit Survey  View Results

Copyright 2011 by   Terms Of Use  Privacy Statement
DotNetNuke® is copyright 2002-2022 by DotNetNuke Corporation