Change Section Style Programmatically

5 posts, 2 answers
  1. Stergios
    Stergios avatar
    13 posts
    Member since:
    Nov 2012

    Posted 10 Nov 2012 Link to this post

    Hi,
    I use the RichTextBox control to display a document composed by a number of Sections (Telerik.Windows.Documents.Model.Section). I want to programmatically change the border color when a user moves the cursor over a section or presses the left mouse button on a section.

    How can I implement this functionality to determine the selected Section and then change its styling properties?

    Thanks
  2. Answer
    Martin Ivanov
    Admin
    Martin Ivanov avatar
    104 posts

    Posted 14 Nov 2012 Link to this post

    Hi Stergios,

    You can use the active editor presenter to determine the document position from a point obtained in a mouse event the following way:

    DocumentPosition position = this.radRichTextBox.ActiveEditorPresenter.GetDocumentPositionFromViewPoint(e.GetPosition(this.radRichTextBox));
    Section section = position.GetCurrentSectionBox().AssociatedSection;

    Such event can be the MouseMove of the RadRichTextBox. For performance reasons you can limit getting the position to several times in a second.

    Having the section you need, you can apply any style.

    Don't hesitate to contact us if you have other questions.

    All the best,
    Martin
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. DevCraft banner
  4. Iva Toteva
    Admin
    Iva Toteva avatar
    1319 posts

    Posted 14 Nov 2012 Link to this post

    Hi Stergios,

    Having answered your question about getting the current section, we are still a bit confused over what modifications you wish to perform on it. Sections do not have a border color and the relationship between pages and sections is not 1 to 1.

    Could you share some details on your goal? What exactly do you wish to change in the document and should it be for presentation purposes only, or should be persisted when you save the document?

    Looking forward to your reply.

    Kind regards,
    Iva Toteva
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  5. Stergios
    Stergios avatar
    13 posts
    Member since:
    Nov 2012

    Posted 15 Nov 2012 Link to this post

    Hello Iva,

    I want to implement the following scenario:
    - My content is composed by individual blocks of information defined in xml files.
    - Each block has a descriptive content (text, tables etc) and an associated image.
    - All the blocks should be displayed on the same page as a scrollable flow, while the user will be able to select a single block. 
    - Upon selection, the block should be highlighted (e.g. by setting a border around it or by changing its background color) and the corresponding image will be displayed. 

    I've successfully implemented a prototype using the standard silverlight RichTextBox control using a ListBox as the flow container and RichTextBox controls as ListBox items, represanting each block of information.

    Now I want to extend this prototype using the RadRichTextBox instead of the standard RichTextBox control in order to use its built-in capabilities for searching, zooming and pdf exporting. Of course I could use a StackPanel or a ListBox and create a list of RadRichTextBox controls, but then I have to orchestrate the functionalities because searching, zooming and exporting have to apply to all the RadRichTextBoxes at once. Also, by using multiple RichTextBox controls I've notice that the performance is slow (when setting the RadRichTextBox Document property).

    So, I decided to create a single RadRichTextBox (flowing mode) to hold the different blocks of information as Sections. Using this approach, zooming, searching and exporting is siplified but I have to solve the problem of Section selection.  

    Best Regards,
    Stergios
  6. Answer
    Boby
    Admin
    Boby avatar
    595 posts

    Posted 19 Nov 2012 Link to this post

    Hello Stergios,
    Similar behavior can be achieved using custom layers. Please find attached a demo which "selects" the clicked Section using the SelectedSectionsLayer class and the Section.Tag property. Similar demo, highlighting current word/line, can be found it the online examples.
    Note that the attached demo will work correctly only in Flow layout mode, where each section has exactly one section layout box.

    Don't hesitate to contact us if you have further questions.



    Greetings,
    Boby
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top
DevCraft banner