-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExtensions.cs
93 lines (88 loc) · 3.2 KB
/
Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Animation;
namespace NutzCode.MPVPlayer.WPF.Wrapper
{
public static class Extensions
{
public static void VisbilityWithFade(this UIElement v, Visibility visible)
{
List<UIElement> c = new List<UIElement>() {v};
c.VisbilityMembersWithFade(visible);
}
public static void VisbilityMembersWithFade(this IEnumerable<UIElement> v, Visibility visible)
{
var uiElements = v as IList<UIElement> ?? v.ToList();
uiElements.VisbilityMembers(Visibility.Visible);
if (visible==Visibility.Visible)
return;
DoubleAnimation danim = new DoubleAnimation
{
From = 1.0,
To = 0.0,
FillBehavior = FillBehavior.Stop,
Duration = new Duration(TimeSpan.FromSeconds(0.5))
};
Storyboard s= new Storyboard();
s.Children.Add(danim);
foreach (UIElement visual in uiElements)
{
visual.Visibility = Visibility.Visible;
}
foreach (UIElement c in uiElements)
{
Storyboard.SetTarget(danim, c);
}
Storyboard.SetTargetProperty(danim, new PropertyPath(UIElement.OpacityProperty));
s.Completed += delegate { uiElements.VisbilityMembers(visible); };
s.Begin();
}
public static void VisbilityMembers(this IEnumerable<UIElement> v, Visibility visible)
{
foreach (UIElement visual in v)
{
visual.Visibility = visible;
}
}
public static T GetDefaultValue<T>(this DependencyProperty d)
{
return (T) d.DefaultMetadata.DefaultValue;
}
public static void GenerateLanguages(this ComboBox box)
{
foreach (ComboBoxItem b in Models.Language.Languages.Select(a => new ComboBoxItem { Content = a.Name+" ("+a.Code3+")", Tag = a.Code3 }))
{
b.Background = new SolidColorBrush(Color.FromRgb(0x30, 0x30, 0x30));
b.Foreground = new SolidColorBrush(Colors.White);
box.Items.Add(b);
}
}
public static List<string> GetLanguages(this string setting)
{
List<string> ret = new List<string>();
foreach (string s in setting.Split(',').Select(a=>a.Trim()))
{
string n = Models.Language.Languages.FirstOrDefault(a => a.Code3.Equals(s, StringComparison.InvariantCultureIgnoreCase))?.Name;
if (n != null)
{
if (!ret.Contains(n))
ret.Add(n);
}
}
return ret;
}
public static ComboBoxItem GetItemByTag(this ComboBox c, string tag)
{
foreach (ComboBoxItem cd in c.Items)
{
if (((string) cd.Tag) == tag)
return cd;
}
return null;
}
}
}