Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

displaying clickable text WPF

Tags:

c#

wpf

xaml

I want to present some text in the GUI and give the user that ability to double click it. I want to catch this event and deal with it.

I thought to do it like this :

 <TextBlock   
        Height="39" 
        TextElement.FontSize="18" 
        FontFamily="Verdana"
        HorizontalAlignment="Left"
        VerticalAlignment="Center"
        Name="Filelink"
        Padding="5,0,0,0"
        TextDecorations="Underline"
        Text="{Binding Path=FilePath}"/>

But seems that it's not easy to deal with clicks in TextBlock .

Any ideas what is the best way to present a click able text.

Thanks.

like image 331
Night Walker Avatar asked Oct 20 '11 21:10

Night Walker


1 Answers

If you want clickable text you can just restyle a Button:

<Button Content="Text here" Click="Click_Handler">
    <Button.Template>
        <ControlTemplate TargetType="{x:Type Button}">
            <ContentPresenter />
        </ControlTemplate>
    </Button.Template>
</Button>

Also see this question.

like image 57
H.B. Avatar answered Oct 09 '22 03:10

H.B.