Add new filter fuatures

This commit is contained in:
azakhi
2018-08-29 20:12:02 +03:00
parent a09f0a5090
commit 78b4ddc862
78 changed files with 911 additions and 231 deletions

View File

@@ -0,0 +1,65 @@
using System;
using System.ComponentModel;
using System.Linq;
using System.Windows.Markup;
namespace Filtration.Common.Extensions
{
public class EnumerationExtension : MarkupExtension
{
private Type _enumType;
public EnumerationExtension(Type enumType)
{
if (enumType == null) throw new ArgumentNullException(nameof(enumType));
EnumType = enumType;
}
public Type EnumType
{
get
{
return _enumType;
}
private set
{
if (_enumType == value) return;
var enumType = Nullable.GetUnderlyingType(value) ?? value;
if (enumType.IsEnum == false) throw new ArgumentException("Type must be an Enum.");
_enumType = value;
}
}
public override object ProvideValue(IServiceProvider serviceProvider)
{
var enumValues = Enum.GetValues(EnumType);
return (from object enumValue in enumValues
select new EnumerationMember { Value = enumValue, Description = GetDescription(enumValue) }).ToArray
();
}
private string GetDescription(object enumValue)
{
var descriptionAttribute =
EnumType.GetField(enumValue.ToString())
.GetCustomAttributes(typeof(DescriptionAttribute), false)
.FirstOrDefault() as DescriptionAttribute;
return descriptionAttribute != null ? descriptionAttribute.Description : enumValue.ToString();
}
public class EnumerationMember
{
public string Description { get; set; }
public object Value { get; set; }
}
}
}

View 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;
}
}
}