Radu D
Radu D

Reputation: 3555

Silverlight RichTextBox MouseLeftButtonDown not firing

This is my xamal:

<Grid>
    <Grid.RowDefinitions>
        <RowDefinition Height="auto"></RowDefinition>
        <RowDefinition></RowDefinition>
    </Grid.RowDefinitions>
    <RichTextBox Grid.Row="0" Height="250" x:Name="_richTextBox" MouseLeave="_richTextBox_MouseLeave" MouseEnter="_richTextBox_MouseEnter" MouseLeftButtonDown="_richTextBox_MouseLeftButtonDown"></RichTextBox>
    <Button Grid.Row="1" Content="Button" x:Name="_buttonColor" Click="ButtonColor_Click"></Button>
</Grid>

The problem is that mouse enter/leave events trigger and the mouse down does not trigger. Do you know which can be the problem?

I noticed now that the click fires only when I click on the rich text box margin. Can I get the click event in the richtextbox content?

Upvotes: 1

Views: 1077

Answers (2)

Radu D
Radu D

Reputation: 3555

I finally found a way to fix this problem. The idea is to create a new CustomRichTextEditor that inherits from the original one and override the mouse events.

 public class CustomRichTextArea : RichTextBox
 {
    protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
    {
        base.OnMouseLeftButtonDown(e);
        //handle mouse event here 
    }
 }

I hope this helps.

Upvotes: 2

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93561

The content of the textbox is [lots of] other controls, so I imagine the mouse down event is handled by them.

You need to add a mouse down handler to all child elements of the RichTextBox as they are not bubbling that event back to the parent.

If I get a chance I will post a test/sample tonight.

Upvotes: 0

Related Questions