Skip to content

Commit 01e892a

Browse files
committed
Set Foreground Colors in InfoBox to the current SelectedAccent Color;
Made DragArea slightly bigger;
1 parent 4240b2b commit 01e892a

File tree

6 files changed

+83
-39
lines changed

6 files changed

+83
-39
lines changed

QuickNoteWidget/Converter/AccentToColorConverter.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ namespace QuickNoteWidget.Converter
66
{
77
public class AccentToColorConverter : IValueConverter
88
{
9+
public string Convert(string value)
10+
{
11+
return Convert(value, null, null, null).ToString();
12+
}
13+
14+
915
/// <summary>
10-
/// map MahApps.ColorScheme to according Hex values
16+
/// Convert MahApps.ColorScheme to according Hex values
1117
/// Hex values taken from MahApps Source Code
1218
/// https://github.com/MahApps/MahApps.Metro
1319
/// </summary>
@@ -16,8 +22,6 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
1622
string accent = (string)value;
1723
switch (accent)
1824
{
19-
20-
2125
case "Red": return "#FFE51400";
2226
case "Green": return "#FF60A917";
2327
case "Blue": return "#FF0078D7";
@@ -44,6 +48,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
4448
default: return "Cyan";
4549
}
4650
}
51+
4752

4853
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
4954
{

QuickNoteWidget/InfoWindow.xaml

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,28 @@
33
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
44
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
55
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
6+
xmlns:mahapps="http://metro.mahapps.com/winfx/xaml/controls"
67
xmlns:local="clr-namespace:QuickNoteWidget"
8+
Loaded="Window_Loaded"
79
mc:Ignorable="d"
810
WindowStyle="None"
911
Topmost="True"
1012
ResizeMode="NoResize"
1113
Title="InfoWindow"
12-
Height="243.667"
14+
Height="243"
1315
Width="336">
16+
<Window.Resources>
17+
<Style TargetType="TextBlock">
18+
<Setter Property="VerticalAlignment"
19+
Value="Top" />
20+
<Setter Property="HorizontalAlignment"
21+
Value="Left" />
22+
<!--<Setter Property="Foreground" Value="Red" />-->
23+
</Style>
24+
</Window.Resources>
1425
<Border BorderBrush="Black"
1526
BorderThickness="1">
16-
<Grid x:Name="mainGrid">
17-
<Grid.Resources>
18-
<Style TargetType="TextBlock">
19-
<Setter Property="VerticalAlignment"
20-
Value="Top" />
21-
<Setter Property="HorizontalAlignment"
22-
Value="Left" />
23-
</Style>
24-
</Grid.Resources>
27+
<Grid x:Name="mainGrid">
2528
<TextBlock Text="Github:"
2629
TextDecorations="Underline"
2730
Margin="10,16,0,0" />
@@ -46,16 +49,16 @@
4649
Margin="25,110,0,0" />
4750
<TextBlock Text="Icons from Icons8"
4851
Margin="25,131,0,0" />
52+
<TextBlock Text="ICSharp.AvalonEdit"
53+
Margin="25,152,0,0" />
54+
<TextBlock Text="Microsoft.WindowsAPICCodePack"
55+
Margin="25,173,0,0" />
4956
<Button VerticalAlignment="Bottom"
5057
Content="Close"
5158
Style="{DynamicResource MahApps.Styles.Button.Square.Accent}"
5259
Margin="10,0,10,10"
5360
x:Name="btnClose"
5461
Click="btnClose_Click" />
55-
<TextBlock Text="ICSharp.AvalonEdit"
56-
Margin="25,152,0,0" />
57-
<TextBlock Text="Microsoft.WindowsAPICCodePack"
58-
Margin="25,173,0,0" />
5962
</Grid>
6063
</Border>
6164
</Window>

QuickNoteWidget/InfoWindow.xaml.cs

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
using System.Windows;
22
using System.Windows.Controls;
33
using System.Windows.Input;
4+
using System.Linq;
5+
using System.Collections.Generic;
6+
using System.Windows.Media;
7+
using QuickNoteWidget.Converter;
8+
using System;
49

510
namespace QuickNoteWidget
611
{
712
public partial class InfoWindow : Window
813
{
14+
15+
private string _currentAccent;
916
public InfoWindow(string currentAccent)
1017
{
1118
InitializeComponent();
12-
13-
Style textBlockForegroundStyle = new Style(typeof(TextBlock));
14-
textBlockForegroundStyle.Setters.Add(new Setter()
15-
{
16-
Property = TextBlock.ForegroundProperty,
17-
Value = currentAccent
18-
});
19-
20-
// TODO: apply styles to all TextBox
19+
_currentAccent = currentAccent;
2120
}
2221

2322

23+
2424
private void btnClose_Click(object sender, RoutedEventArgs e)
2525
{
2626
this.Close();
@@ -32,5 +32,42 @@ protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
3232
base.OnMouseLeftButtonDown(e);
3333
DragMove();
3434
}
35+
36+
private void Window_Loaded(object sender, RoutedEventArgs e)
37+
{
38+
SetAccentToTextBlock();
39+
}
40+
41+
private void SetAccentToTextBlock()
42+
{
43+
IEnumerable<TextBlock> textBlocks = GetElementByType<TextBlock>(this);
44+
foreach (TextBlock textBlock in textBlocks)
45+
{
46+
string hexColor = new AccentToColorConverter().Convert(_currentAccent);
47+
Brush brushColor = new BrushConverter().ConvertFromString(hexColor) as Brush;
48+
textBlock.Foreground = brushColor;
49+
textBlock.InvalidateVisual();
50+
}
51+
}
52+
53+
private static IEnumerable<T> GetElementByType<T>(DependencyObject depObj) where T : DependencyObject
54+
{
55+
if (depObj == null)
56+
yield return (T)Enumerable.Empty<T>();
57+
58+
for (int i = 0; i < VisualTreeHelper.GetChildrenCount(depObj); i++)
59+
{
60+
DependencyObject ithChild = VisualTreeHelper.GetChild(depObj, i);
61+
62+
if (ithChild == null)
63+
continue;
64+
65+
if (ithChild is T t)
66+
yield return t;
67+
68+
foreach (T childOfChild in GetElementByType<T>(ithChild))
69+
yield return childOfChild;
70+
}
71+
}
3572
}
3673
}

QuickNoteWidget/MainWindow.xaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@
1212
KeyDown="Window_KeyDown"
1313
WindowStyle="None"
1414
Title="MainWindow"
15-
Height="349"
15+
Height="350"
1616
Topmost="{Binding Settings.OnTop}"
1717
ShowInTaskbar="{Binding Settings.ShowInTaskbar}"
1818
ContextMenu="{DynamicResource contextMenu}"
19-
Width="551">
19+
Width="550">
2020
<Window.Resources>
2121
<converter:AccentToColorConverter x:Key="AccentToColorConverter" />
2222
<converter:StringToFontStyleConverter x:Key="fontStyle" />
@@ -91,7 +91,7 @@
9191
DockPanel.Dock="Bottom"
9292
Visibility="{Binding Settings.DisplayDetails, Converter={StaticResource BoolToVisibilityCollapsedConverter}}"
9393
VerticalAlignment="Bottom"
94-
Margin="10,0,10,10"
94+
Margin="12,6,12,10"
9595
Background="{Binding StatusBarBackground, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
9696
<StatusBarItem>
9797
<StackPanel Orientation="Horizontal">
@@ -104,10 +104,10 @@
104104
</StatusBar>
105105
<avalonedit:TextEditor x:Name="tbxMultiLine"
106106
DockPanel.Dock="Top"
107-
Margin="10"
107+
Margin="12,12,12,6"
108108
AllowDrop="True"
109109
mahapps:TextBoxHelper.ClearTextButton="True"
110-
mahapps:TextBoxHelper.SelectAllOnFocus="True"
110+
mahapps:TextBoxHelper.SelectAllOnFocus="True"
111111
TextChanged="TbxMultiLine_TextChanged"
112112
Document="{Binding MultiLine, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource StringToTextDocumentConverter}}"
113113
LineNumbersForeground="{Binding SelectedAccent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource AccentToColorConverter}}"

QuickNoteWidget/MainWindow.xaml.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,10 @@ protected override void OnClosed(EventArgs e)
7777

7878
private void Info_Click(object sender, RoutedEventArgs e)
7979
{
80-
var info = new InfoWindow(_mainWindowViewModel.SelectedAccent ?? "Cyan");
81-
info.Show();
80+
var _infoWindow = new InfoWindow(_mainWindowViewModel.SelectedAccent ?? "Cyan");
81+
_infoWindow.Show();
8282
}
8383

84-
8584
// React to ctrl + mouse wheel
8685
private void tbxMultiLine_PreviewMouseWheel(object sender, MouseWheelEventArgs e)
8786
{

QuickNoteWidget/MainWindowViewModel.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ public class MainWindowViewModel : ViewModelBase
1313
#region Constants
1414
private const string WHITE = "#FFFFFF";
1515
private const string BLACK = "#252525"; // Based on Theme colord "Dark"
16-
private const string GRAY = "#3A3A3A"; // slightly lighter than BLACK
17-
private const string WHITE_SMOKE = "#EAEAEA"; // slightly darker than "WhiteSmoke"
16+
private const string GRAY = "#616161"; // slightly lighter than BLACK
17+
private const string LIGHT_GRAY = "#EAEAEA"; // slightly darker than "WhiteSmoke"
1818
private const string NORMAL = "Normal";
1919
private const string ITALIC = "Italic";
2020
private const string STRIKETHROUGH = "Strikethrough";
@@ -55,6 +55,7 @@ public string MultiLine
5555

5656
public ICommand ClearMultiLineCommand { get; set; }
5757

58+
5859
public MainWindowViewModel()
5960
{
6061
LoadAvailableThemes();
@@ -73,7 +74,6 @@ private void Init()
7374

7475

7576
#region Settings
76-
//public Settings Settings { get; set; }
7777

7878
private Settings _settings;
7979

@@ -104,7 +104,7 @@ public string SelectedTheme
104104
{
105105
SetProperty(ref _selectedTheme, value, () => SelectedTheme);
106106
StatusBarBackground = this.SelectedTheme == ThemeManager.BaseColorLight ? WHITE : BLACK;
107-
DragAreaColor = this.SelectedTheme == ThemeManager.BaseColorLight ? WHITE_SMOKE : GRAY;
107+
DragAreaColor = this.SelectedTheme == ThemeManager.BaseColorLight ? LIGHT_GRAY : GRAY;
108108
ThemeChanger.ChangeTheme(this.SelectedAccent, this.SelectedTheme);
109109
ThemeSelectionChanged();
110110
}
@@ -147,7 +147,7 @@ private void ThemeSelectionChanged()
147147
if (!String.IsNullOrEmpty(SelectedTheme))
148148
MultiLineTextForegroundColor = SelectedTheme == ThemeManager.BaseColorLight ? BLACK : WHITE;
149149
else
150-
MultiLineTextForegroundColor = WHITE_SMOKE;
150+
MultiLineTextForegroundColor = LIGHT_GRAY;
151151
}
152152

153153
#endregion Settings

0 commit comments

Comments
 (0)