Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Clickable" textblock?

Tags:

I have a WP7 app where I would like to have a "clickable" TextBlock area, that when a user clicks on the TextBlock, it puts it into edit mode (a different control). This would add another explicit step for a user before editing text.

There is no click event for the TextBlock (which doesn't surprise me).

Is there any way to do this? Wrapped in another control, or something similar?

like image 322
pearcewg Avatar asked Nov 29 '10 21:11

pearcewg


2 Answers

Yes, there is a click event. Its called MouseLeftButtonDown

textBlock1.MouseLeftButtonDown +=new MouseButtonEventHandler(textBlock1_MouseLeftButtonDown);

private void textBlock1_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{

}
like image 183
alansiqueira27 Avatar answered Sep 28 '22 01:09

alansiqueira27


I have solved this by creating a Button with the TextBlock inside its Template like this:

<Button Click="button_Click">
    <Button.Template>
        <ControlTemplate>
            <TextBlock ... />
        </ControlTemplate>
    </Button.Template>
</Button>

It's a bit more markup, but you don't need to write any code, it is provided by the framework and works properly.

like image 21
Mark Vincze Avatar answered Sep 28 '22 00:09

Mark Vincze