How to specify static C1RichTextBox content in XAML?

Silverlight

Collaborate with ComponentOne technical experts and fellow developers.

How to specify static C1RichTextBox content in XAML?

  • rated by 0 users
  • This post has 10 Replies |
  • 2 Followers
  • We have downloaded the 30 day trial version in order to eval the product. In our app we are rendering preexisting XML content from a database into XAML for display in a SL3 client. The C1RichTextBox appears to support much of the functionality we need in that display; however we are unable to figure out how to render that XML into XAML that uses C1RichTextBox and friends.

    In fact we are immediatly stumped when we attempt to put *anything* inside the C1RichTextBox and get an error saying C1RichTextBox cannot have any direct content. We have seen comments on your web site indicating that we should be able to simply substitute C1RichTextBox for the existing SL3 TextBox control; however this error message seems to contradict that assertion.

    So, is there a way to express C1RichTextBox content at the XAML level or must it be done programmatically?

    Thanks

    Bill

  • There are several ways you can specify static C1RichTextBox content in XAML. First you can just set the Text property, this would be the equivalent of what you can do with a SL3 TextBox:

    \
    <c1rtb:C1RichTextBox Text="some unformatted text" />

    Similar to this you can set the Html property:

    <c1rtb:C1RichTextBox Html="an &lt;b&gt;html&lt;/b&gt; document" />

    And finally you can directly set the C1Document:

    <c1rtb:C1RichTextBox>
        <c1rtb:C1RichTextBox.Document>
            <c1doc:C1Document>
                <c1doc:C1Paragraph>
                    <c1doc:C1Run Text="some bold text" FontWeight="Bold"/>
                </c1doc:C1Paragraph>
            </c1doc:C1Document>
        </c1rtb:C1RichTextBox.Document>
    </
    c1rtb:C1RichTextBox>

    This is more verbose than the first two, but it's also more flexible. It provides direct access to all the features in C1Document.

  • Max

      Thanks for the reply. This is exactly what we were looking for and will allow us to proceed with our eval of the product. The docs for your Silverlight package seem to lack examples in general and seem to be strictly oriented to the programmatic api. Is this sort of information available elsewhere on the web site?

    Thanks again for the help,

    Bill

  • The documentation shipped with the studio is all we currently have (you can also access it here). Note that all properties of the programmatic api can be set in XAML, so the documentation applies for content initialization in XAML as well as code.

  • Max

      Yes, we attempted to extrapolate from the API docs to XAML, but were unsuccessful as we tried (for instance) to create a C1Document element as a child to the c1RichTextBox element. Obviously that doesn't work without the intervening C1RichTextBox.C1Document element. Perhaps that's somehow obvious, but it certainly wasn't (and still isn't) to me. How is it that users are supposed to intuit the need for this intervening element? Maybe there's something about Type <-> XAML mapping I don't understand yet.

    Bill

  • Whenever you need to set a property in XAML that can't be parsed from a string you do something like:

    <object>
        <object.property>
            propertyValueAsObjectElement
        
    </object.property>
    </
    object>

    That's how "C1RichTextBox.Document" sets the Document property (for more info see this msdn article). In some cases we can use the ContentProperty attribute to configure a property that will be used by default when adding direct content in XAML, that's why no special tag is needed when setting the content of C1Document (although using a C1Document.Blocks tag would also work). I don't remember exactly why we didn't use the ContentProperty attribute with C1RichTextBox.Document, I'll look into it.

    Thanks for the feedback Bill. By the way, if you have any suggestion on how to improve the RichTextBox (besides better docs ;) now would be a great time to mention it, we are on the middle of a big rewrite of the RichTextBox internals.

  • We're pretty early in our project so I'm sure we'll uncover additional needs/requirements as we move forward; however at the moment the two known needs are strikethru text decoration, and some sort of support for "annotating" a RTB (as in "sticky notes"). I believe WPF has an annotation namespace, but haven't investigated it yet.

    Thanks,

    Bill

  • Strikethrough is currently supported, just assign the TextDecoration property of any C1TextElement to C1TextDecorations.Strikethrough. The only problem with strikethrough is that it is not currently serialized to html, that will be corrected in the next release.

    Implementing annotations in the current RichTextBox is possible, but not easy, it will be a lot easier in the next release. We'll try to make a sample that implements them.

    Regards

  • That's good news about both strikethrough and annotations, although a search of the ComponentOne Studio yields no reference to strikethrough. Any time frame yet for the next release?

    Bill

  • The next release will be on December.
  • Hi, 

    I am correcting Max, the next release is scheduled for November, probably the 15th.

    We do three mayor release each year: V1, V2 and V3 in March, July and November respectively.


    Regards

    Follow me: Twitter.com/leovernazza/

Page 1 of 1 (11 items)