Add new filter fuatures
This commit is contained in:
40
Filtration.Common/Extensions/HyperlinkExtensions.cs
Normal file
40
Filtration.Common/Extensions/HyperlinkExtensions.cs
Normal file
@@ -0,0 +1,40 @@
|
||||
// Taken from http://stackoverflow.com/a/11433814/4153185
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Navigation;
|
||||
|
||||
namespace Filtration.Common.Extensions
|
||||
{
|
||||
public static class HyperlinkExtensions
|
||||
{
|
||||
public static bool GetIsExternal(DependencyObject obj)
|
||||
{
|
||||
return (bool)obj.GetValue(IsExternalProperty);
|
||||
}
|
||||
|
||||
public static void SetIsExternal(DependencyObject obj, bool value)
|
||||
{
|
||||
obj.SetValue(IsExternalProperty, value);
|
||||
}
|
||||
public static readonly DependencyProperty IsExternalProperty =
|
||||
DependencyProperty.RegisterAttached("IsExternal", typeof(bool), typeof(HyperlinkExtensions), new UIPropertyMetadata(false, OnIsExternalChanged));
|
||||
|
||||
private static void OnIsExternalChanged(object sender, DependencyPropertyChangedEventArgs args)
|
||||
{
|
||||
var hyperlink = sender as Hyperlink;
|
||||
|
||||
if ((bool)args.NewValue)
|
||||
{
|
||||
if (hyperlink != null) hyperlink.RequestNavigate += Hyperlink_RequestNavigate;
|
||||
}
|
||||
else if (hyperlink != null) hyperlink.RequestNavigate -= Hyperlink_RequestNavigate;
|
||||
}
|
||||
|
||||
private static void Hyperlink_RequestNavigate(object sender, RequestNavigateEventArgs e)
|
||||
{
|
||||
Process.Start(new ProcessStartInfo(e.Uri.AbsoluteUri));
|
||||
e.Handled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user