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

Buttons and Editor in separate views using MVVM and Unity

2 Answers 57 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Ahmet Karakoc
Top achievements
Rank 1
Ahmet Karakoc asked on 02 Sep 2010, 02:45 PM
Hi,

We have a silverlight application with a menu view containing the ribbonbar and another view with the richtextbox. Is it possible to edit the contents of the richtextbox using prism commands and RichTextBoxCommands when user clicks a ribbonbarbutton eg. bold, insert image etc.

Update: We managed to make the views interact using some code like this:

public RichTextBoxViewModel(IEventAggregator eventAggregator, IUnityContainer container)
        {
            _container = container;
  
            eventAggregator.GetEvent<HtmlEditorCommandsEvent>().Subscribe(OnHtmlEditorCommand, true);
        }
  
        private void OnHtmlEditorCommand(string param)
        {
            var radRichTextBox = _container.Resolve<RadRichTextBox>();
              
            switch (param)
            {
                case HtmlEditorCommands.InsertPictureCommand:
                    var command = new InsertPictureCommand(radRichTextBox);
                    command.Execute();
                    break;
                default:
                    break;
            }
        }

But it would be better to resolve RadRichTextBox in our menu view so we can do something like this in the ribbonbar:
DataContext="{Binding Path=Commands,ElementName=_container.Resolve<RadRichTextBox>()}"









How can we achieve this in the menu viewmodel?



Br,
Ahmet

2 Answers, 1 is accepted

Sort by
0
Ahmet Karakoc
Top achievements
Rank 1
answered on 03 Sep 2010, 12:15 PM
When using above code and debugging I get an exception saying "Dialogs must be initiated by user" for the insert picture command. However, the dialog shows and inserts an image when we are not in debug mode.

I tested the same for insert hyperlink command and it is not responding or giving exception at all.

/Ahmet
0
Ivailo Karamanolev
Telerik team
answered on 03 Sep 2010, 04:18 PM
Hi Ahmet Karakoc,

In scenarios like yours, using the RadRichTextBox API in your own custom control logic is the appropriate way to go. The exceptions you're seeing are part of the Silverlight security model and I'd suggest you review these details further.
Get back to us if we can assist you any more.

All the best,
Ivailo
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
RichTextBox
Asked by
Ahmet Karakoc
Top achievements
Rank 1
Answers by
Ahmet Karakoc
Top achievements
Rank 1
Ivailo Karamanolev
Telerik team
Share this question
or