Repository navigation
Expand file tree
/
Copy pathInfoWindow.xaml.cs
More file actions
73 lines (59 loc) · 2.04 KB
/
Copy pathInfoWindow.xaml.cs
File metadata and controls
73 lines (59 loc) · 2.04 KB
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
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Linq;
using System.Collections.Generic;
using System.Windows.Media;
using QuickNoteWidget.Converter;
using System;
namespace QuickNoteWidget
{
public partial class InfoWindow : Window
{
private string _currentAccent;
public InfoWindow(string currentAccent)
{
InitializeComponent();
_currentAccent = currentAccent;
}
private void btnClose_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
DragMove();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
SetAccentToTextBlock();
}
private void SetAccentToTextBlock()
{
IEnumerable<TextBlock> textBlocks = GetElementByType<TextBlock>(this);
foreach (TextBlock textBlock in textBlocks)
{
string hexColor = new AccentToColorConverter().Convert(_currentAccent);
Brush brushColor = new BrushConverter().ConvertFromString(hexColor) as Brush;
textBlock.Foreground = brushColor;
textBlock.InvalidateVisual();
}
}
private static IEnumerable<T> GetElementByType<T>(DependencyObject depObj) where T : DependencyObject
{
if (depObj == null)
yield return (T)Enumerable.Empty<T>();
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
{
DependencyObject ithChild = VisualTreeHelper.GetChild(depObj, i);
if (ithChild == null)
continue;
if (ithChild is T t)
yield return t;
foreach (T childOfChild in GetElementByType<T>(ithChild))
yield return childOfChild;
}
}
}
}