Bind to rounted command in Caliburn.Micro / disable delete command in richTextBox in user control

Feb 10, 2011 at 5:14 PM

Hi, is it possible make binding on rountend commads in caliburn micro framework? I would like make a binding on Delete command because I need disable this command in richTextBoxControl which is in user control.

Fist I try use Message.Atach and bind on Copy command method from view model class, of cource it could not work.

<Controls:BindableRichTextBox   Document="{Binding Path=Conversation,Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
           VerticalScrollBarVisibility="Auto" 
           Micro:Message.Attach="[Command Copy]=[Action Copy()]" />

I need only disable delete command, so I try make this: (code is from user control)

   <Controls:BindableRichTextBox  Document="{Binding Path=Conversation,Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                 VerticalScrollBarVisibility="Auto" >

        <Controls:BindableRichTextBox.CommandBindings>
                <CommandBinding Command="Delete" CanExecute="CommandBinding_CanExecute"/>
        </Controls:BindableRichTextBox.CommandBindings>
        </Controls:BindableRichTextBox>

and in code behind I have this:

    private void CommandBinding_CanExecute(object sender, System.Windows.Input.CanExecuteRoutedEventArgs e)
    {
        e.CanExecute = false;
        e.Handled = true;
    }

User control is Active as tab item in shell.

I run app, and make select some text in richTextBox control a press delete, event CommandBinding_CanExecute is not called.

I suppose if I pressed delete key it call delete command on richTextBox control, is it true?

I don’t understand why is not called.