Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add an event when I click on a TextBlock?

Tags:

wpf

Can I know how to add an event when I click on a TextBlock? I can't find the onClick on the TextBlock. Does anyone know what is the name of the event?

code:

<TextBlock Name="Title" Click="?" />
like image 946
De Bruce Lee Avatar asked Nov 26 '12 10:11

De Bruce Lee


2 Answers

Just use the "PreviewMouseDown" event. Good luck!

like image 131
0070 Avatar answered Oct 18 '22 03:10

0070


You can use an InputBinding:

<TextBlock Text="{Binding SomeText}">
    <TextBlock.InputBindings>
        <MouseBinding Command="{Binding SomeCommand}" MouseAction="LeftClick" />
    </TextBlock.InputBindings>
</TextBlock>

Source: https://learn.microsoft.com/en-us/dotnet/api/system.windows.input.inputbinding

like image 8
MovGP0 Avatar answered Oct 18 '22 03:10

MovGP0