Here I will post problems I and my colleagues met and solutions we found.

Wednesday, September 10, 2008

Hyperlinks in WPF Continued

I wrote before about using hyperlinks in WPF. For my new side project I need to switch from hypertext to the simple text depending on availability of URL. Switching to simple text seemed easy, just assigning text value to the Text property worked. Switching back was not obvious for me.

Then I found that TextBlock has Inlines property. The code became this:

tHypertext.Inlines.Clear();
if (!string.IsNullOrEmpty(uri))
{
if (!string.IsNullOrEmpty(value))
tHypertext.Inlines.Add(value);
tHypertext.NavigateUri = new Uri(uri);
tTextBlock.Inlines.Clear();
tTextBlock.Inlines.Add(tWord);
}
else
{
tTextBlock.Text = value;
tHypertext.NavigateUri = null;
}

Where TextBlock and Hypertext are from previouse example

No comments: