Try to parse the url, similar to int.TryParse
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Documents;
using System.Windows;
using System.Windows.Media;
using System.Diagnostics;
using System.Windows.Controls;
using System.Windows.Input;
namespace DigiFlare.DigiTweet.UI
{
public class Utils
{
#region Helper Methods
/// <summary>
/// Try to parse the url, similar to int.TryParse
/// </summary>
/// <param name="url"></param>
/// <param name="color"></param>
/// <param name="hyperlink"></param>
/// <returns></returns>
private static bool TryParseUrl(string url, out Hyperlink hyperlink)
{
hyperlink = null;
// check input url
if (string.IsNullOrEmpty(url))
{
return false;
}
// try parsing url
if (0 == url.IndexOf("http://", StringComparison.InvariantCultureIgnoreCase))
{
try
{
Uri uri = new Uri(url);
Hyperlink link = new Hyperlink { NavigateUri = uri };
link.Inlines.Add(url);
// set output value
hyperlink = link;
return true;
}
catch (Exception) { }
}
return false;
}
#endregion
}
}
Related examples in the same category