Вопрос

iHi, in my Windows Phone application in View I have:

 <TextBlock x:Name="lblink" FontSize="15" Margin="30,0,24,0"  Height="30" Text="*use a email@mail.com if you are not the member"  TextWrapping="Wrap"  HorizontalAlignment="Left" />

I need to make the functionality like this: when I click on the text: "email@mail.com" it should be called an event

How can I resolve this issue?

Это было полезно?

Решение

So, try using following code:

<StackPanel Orientation="Horizontal">
            <TextBlock Text="*use a "/>
            <TextBlock Text="email@mail.com" Tap="TextBlock_Tap"/>
            <TextBlock Text=" if you are not the member"/>

        </StackPanel>

Другие советы

Why not use a HyperlinkButton. This allows you to set text in the Content property, and then implement the Click event handler.

Alternatively, you could use a Template for a button control:

<phone:PhoneApplicationPage.Resources>

    <ControlTemplate x:Key="MyButtonTemplate" TargetType="Button">
        <TextBlock x:Name="lblink" FontSize="15" Margin="30,0,24,0"  Height="30" Text="*use a email@mail.com if you are not the member"  TextWrapping="Wrap"  HorizontalAlignment="Left" />
    </ControlTemplate>

</phone:PhoneApplicationPage.Resources>

Which is implemented as follows:

<Button x:Key="MyButton" Template="{StaticResource MyButtonTemplate}" Click="MyButton_Click" />

You can then do whatever you need to in the MyButton_Click event handler.

                <TextBlock>
                    <Run Text="*use a " />
                    <Hyperlink Click="[click event]">
                        <Run Text="email@mail.com" />
                    </Hyperlink>
                    <Run Text=" if you are not the member" />
                </TextBlock>

This provides you the clickable region I think you are looking for.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top