You can try to get Hyperlink
from TextBlock
's Inlines
property, for example :
var h = tbs.Inlines.OfType<Hyperlink>().FirstOrDefault();
Question
I have a canvas on which i have a textBlock, and i have a hyperlink inside textBlock. i can access the canvas on my grid and Textblock on the canvas with following code, but dnt know how to access hyperlink inside textBlock, ANy idea guys ?
canvas+textBlock+hyperlink code:
<Canvas Grid.Column="2" ClipToBounds="True" Name="canMain" Background="Beige" Margin="12,25" Grid.RowSpan="2" >
<TextBlock FontSize="15" Name="tbmarquee" Canvas.Left="10" Width="169">
<Hyperlink NavigateUri="http://www.google.com" RequestNavigate="Hyperlink_RequestNavigate" Cursor="Hand" >
<!--Google page link-->
</Hyperlink>
</TextBlock>
</Canvas>
and i Access the canvas and TextBlock dynamically with following code:
IEnumerable<Canvas> cnvss = this.gride.Children.OfType<Canvas>();
foreach (Canvas cnvs in cnvss)
{
IEnumerable<TextBlock> txs = cnvs.Children.OfType<TextBlock>();
foreach(TextBlock tbs in txs )
{
}
}
How to access the hyperlink ?
Solution
You can try to get Hyperlink
from TextBlock
's Inlines
property, for example :
var h = tbs.Inlines.OfType<Hyperlink>().FirstOrDefault();