This is a migrated thread and some comments may be shown as answers.

Updating Document using MVVM

5 Answers 235 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Marcel
Top achievements
Rank 1
Marcel asked on 30 Sep 2011, 01:52 PM
Hi, 

so i have been changing everything so that it fits into mvvm model. So i have bound my document by using the xamldataprovider and that works fine. But now, when when i use functions such as gotobookmark or try and highlight the text it no longer works. 

I call:

Document.GoToBookMark(bookmarkrange); 

I then attempt to update by calling:
public void UpdateXaml()
{
var xamlProvider = new XamlDataProvider { Xaml = XamlText, RichTextBox = RichTextBox };
xamlProvider.UpdateDocument();
}

but nothing seems to happen. Is this the correct way to update? It is very slow! 

I have also been looking at your searchandhighlight project, this gives an example of how to change the text color using:

 private void buttonClearHighlight_Click()
        {
            foreach (Block block in this.radRichTextBox.Document.Sections.First.Blocks)
            {
                foreach (Span span in block.Children)
                {
                    if (span.HighlightColor == Colors.LightGray)
                    {
                        span.HighlightColor = Colors.Transparent;
                    }
                }
            }
            this.radRichTextBox.UpdateEditorLayout();
        }

This throws lots of exception when I tried to use it. 

Unable to cast object of type 'Telerik.Windows.Documents.Model.BookmarkRangeStart' to type 'Telerik.Windows.Documents.Model.Span'.

Help on these issue would be much appreciated.

5 Answers, 1 is accepted

Sort by
0
Marcel
Top achievements
Rank 1
answered on 03 Oct 2011, 09:48 AM
Any Ideas?

Another example is enabling the spell checker:

RichTextBox.IsSpellCheckingEnabled = true;

The do I call xamlProvider.UpdateDocument(); Because nothing ever seems to happen. 

I have followed this link also http://www.telerik.com/help/silverlight/radrichtextbox-features-data-providers.html, makes no difference.
0
Marcel
Top achievements
Rank 1
answered on 03 Oct 2011, 03:24 PM
Seriously?! No one has tried this... 

I have literally tried everything. I have not been able to successful update the RadRichTextBox on screen using the XamlDataProvider approach. There has got to be away. I have also tried using:

SetupDocument="XamlDataProvider_SetupDocument" Loaded="XamlDataProvider_Loaded"/>

SetupDocument I can only trigger once, that is when I initially create the DataProvider. It was actually easier when i used code behinds and just called this.UpdateLayout(), so there must be away off doing the same thing usign the DataProviders right? 


0
Iva Toteva
Telerik team
answered on 04 Oct 2011, 01:12 PM
Hello Chez,

The string property you have bound the data provider to is only updated when there is a change in the content of the document. Changing the caret position, as well as turning spell checking on and off are not considered document changes. These properties represent features of the rich text box and are not serialized, hence there is no need to update the property.

When it comes to changing the highlight color of a bookmark, this can be done as follows:

private void ChangeForeColorOfBookmarks(Color color)
{
    foreach (BookmarkRangeStart item in this.radRichTextBox.Document.GetAllBookmarks())
    {
        this.radRichTextBox.Document.Selection.SelectAnnotationRange(item);
        this.radRichTextBox.ChangeTextForeColor(color);
    }
}

More information on Bookmarks can be found here.
I hope this helps.

Best wishes,
Iva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Marcel
Top achievements
Rank 1
answered on 04 Oct 2011, 03:47 PM
Do you know how i would do that though without using a code behind? So instead I would be doing it in my ViewModel.
0
Iva Toteva
Telerik team
answered on 07 Oct 2011, 05:27 PM
Hello Chez,

If in the string property you have bound the content of the document through XamlDataProvide specifies a different color for all bookmarks, then you won't need to use code-behind.
However, if this is not the case, there is no other way to apply custom formatting to the document than using code-behind.

Kind regards,
Iva
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
RichTextBox
Asked by
Marcel
Top achievements
Rank 1
Answers by
Marcel
Top achievements
Rank 1
Iva Toteva
Telerik team
Share this question
or