Hi, Anusha
You can use WinRT XAML toolkit to resolve your problem. See some codes below:
<HyperlinkButton Name="ExamplesLink" Click="ExamplesLink_Click"
Extensions:FrameworkElementExtensions.SystemCursor="Hand">
<TextBlock>
<Underline>
<Run Text="Examples"/>
</Underline>
</TextBlock>
</HyperlinkButton>
Also, you can use the RichTextBlock’s tapped event and its GetPositionFromPoint method:
<RichTextBlock IsTextSelectionEnabled="False"
Margin="30"
Width="600"
TextAlignment="Justify"
FontSize="40"
TextWrapping="Wrap"
Tapped="UIElement_OnTapped">
<Paragraph>
<Run Text="HyperlinkButton have the similar purpose of enabling a user to launch a specific URI using a separate browser app." />
<Run Text=". " />
<Underline x:Name="LinkToInfiniteSquare"
Foreground="#FFFF1BF5">
<Run Text="and a HyperlinkButton is a control" />
</Underline>
</Paragraph>
</RichTextBlock>
Code-behind:
private void UIElement_OnTapped(object sender, TappedRoutedEventArgs e)
{
var richTB = sender as RichTextBlock;
var textPointer = richTB.GetPositionFromPoint(e.GetPosition(richTB));
var element = textPointer.Parent as TextElement;
while (element != null && !(element is Underline))
{
if (element.ContentStart != null
&& element != element.ElementStart.Parent)
{
element = element.ElementStart.Parent as TextElement;
}
else
{
element = null;
}
}
if (element == null) return;
var underline = element as Underline;
if (underline.Name == "LinkToInfiniteSquare")
{
Launcher.LaunchUriAsync(new Uri("http://msdn.microsoft.com/en-us/library/windows/apps/windows.ui.xaml.controls.hyperlinkbutton.aspx"));
}
}
Best Wishes!
We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey. Thanks<br/> MSDN Community Support<br/> <br/> Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.
No comments:
Post a Comment