Skip to content

Commit 831974f

Browse files
committed
issue #4: added Transparency Slider
1 parent 01e892a commit 831974f

File tree

3 files changed

+62
-19
lines changed

3 files changed

+62
-19
lines changed

QuickNoteWidget/MainWindow.xaml

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
Title="MainWindow"
1515
Height="350"
1616
Topmost="{Binding Settings.OnTop}"
17-
ShowInTaskbar="{Binding Settings.ShowInTaskbar}"
17+
ShowInTaskbar="{Binding Settings.ShowInTaskbar}" AllowsTransparency="True"
18+
Opacity="{Binding TransparencyValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
1819
ContextMenu="{DynamicResource contextMenu}"
1920
Width="550">
2021
<Window.Resources>
@@ -23,7 +24,10 @@
2324
<converter:StringToTextDecorationConverter x:Key="textDeco" />
2425
<converter:StringToTextDocumentConverter x:Key="StringToTextDocumentConverter" />
2526
<converter:BoolToVisibilityCollapsedConverter x:Key="BoolToVisibilityCollapsedConverter" />
26-
27+
<Style TargetType="TextBlock">
28+
<Setter Property="Foreground"
29+
Value="{Binding SelectedAccent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource AccentToColorConverter}}" />
30+
</Style>
2731
<ContextMenu x:Key="contextMenu">
2832
<MenuItem Header="Select All (Ctrl + A)"
2933
Click="contextSelect_Click" />
@@ -79,11 +83,12 @@
7983
<CheckBox Content="Show in Taskbar"
8084
IsChecked="{Binding Settings.ShowInTaskbar}" />
8185
</MenuItem>
86+
<MenuItem Header="Reset Transperency"
87+
Command="{Binding ResetTransparencyCommand}" />
8288
<MenuItem Header="Info"
8389
Click="Info_Click" />
8490
</ContextMenu>
8591
</Window.Resources>
86-
8792
<Grid Background="{Binding DragAreaColor, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
8893
<DockPanel LastChildFill="True">
8994
<StatusBar Height="23"
@@ -92,22 +97,39 @@
9297
Visibility="{Binding Settings.DisplayDetails, Converter={StaticResource BoolToVisibilityCollapsedConverter}}"
9398
VerticalAlignment="Bottom"
9499
Margin="12,6,12,10"
95-
Background="{Binding StatusBarBackground, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
100+
Background="{Binding StatusBarBackground, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}">
96101
<StatusBarItem>
97102
<StackPanel Orientation="Horizontal">
98-
<TextBlock Text="Word Count: "
99-
Foreground="{Binding SelectedAccent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource AccentToColorConverter}}" />
100-
<TextBlock Text="{Binding WordCount, UpdateSourceTrigger=PropertyChanged}"
101-
Foreground="{Binding SelectedAccent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource AccentToColorConverter}}" />
103+
<TextBlock Text="Word Count: " />
104+
<TextBlock Text="{Binding WordCount, UpdateSourceTrigger=PropertyChanged}" />
105+
</StackPanel>
106+
</StatusBarItem>
107+
<Separator Margin="10,0,10,0"
108+
HorizontalAlignment="Left" />
109+
<StatusBarItem>
110+
<StackPanel Orientation="Horizontal">
111+
<TextBlock Text="Transparency"
112+
Margin="0,0,10,0" />
113+
<Slider Width="100"
114+
Minimum="0.3"
115+
Maximum="1"
116+
Value="{Binding TransparencyValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
117+
<TextBlock Margin="10,0,0,0">
118+
<TextBlock.Inlines>
119+
<Run Text="{Binding TransparencyInPercent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
120+
<Run Text="%" />
121+
</TextBlock.Inlines>
122+
</TextBlock>
102123
</StackPanel>
103124
</StatusBarItem>
104125
</StatusBar>
126+
105127
<avalonedit:TextEditor x:Name="tbxMultiLine"
106128
DockPanel.Dock="Top"
107129
Margin="12,12,12,6"
108130
AllowDrop="True"
109131
mahapps:TextBoxHelper.ClearTextButton="True"
110-
mahapps:TextBoxHelper.SelectAllOnFocus="True"
132+
mahapps:TextBoxHelper.SelectAllOnFocus="True"
111133
TextChanged="TbxMultiLine_TextChanged"
112134
Document="{Binding MultiLine, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, Converter={StaticResource StringToTextDocumentConverter}}"
113135
LineNumbersForeground="{Binding SelectedAccent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource AccentToColorConverter}}"
@@ -116,11 +138,11 @@
116138
WordWrap="True"
117139
PreviewMouseWheel="tbxMultiLine_PreviewMouseWheel" />
118140
</DockPanel>
141+
119142
<tb:TaskbarIcon IconSource=".\Clipboard.ico"
120143
x:Name="TaskbarIcon"
121144
Grid.RowSpan="2"
122145
Grid.ColumnSpan="4"
123-
ContextMenu="{DynamicResource contextMenu}">
124-
</tb:TaskbarIcon>
146+
ContextMenu="{DynamicResource contextMenu}"></tb:TaskbarIcon>
125147
</Grid>
126148
</Window>

QuickNoteWidget/MainWindowViewModel.cs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,29 @@ public class MainWindowViewModel : ViewModelBase
2525
private string _wordCount;
2626
private string _dragAreaColor;
2727
private string _statusBarBackground;
28+
private double _transparencyValue;
29+
private int _transparencyInPercent;
30+
private Settings _settings;
2831

32+
public Settings Settings
33+
{
34+
get { return _settings; }
35+
set { SetProperty(ref _settings, value, () => Settings); }
36+
}
37+
public int TransparencyInPercent
38+
{
39+
get { return _transparencyInPercent; }
40+
set { SetProperty(ref _transparencyInPercent, value, () => TransparencyInPercent); }
41+
}
42+
public double TransparencyValue
43+
{
44+
get { return _transparencyValue; }
45+
set
46+
{
47+
SetProperty(ref _transparencyValue, value, () => TransparencyValue);
48+
TransparencyInPercent = (Int32)(TransparencyValue * 100);
49+
}
50+
}
2951
public string StatusBarBackground
3052
{
3153
get => _statusBarBackground;
@@ -54,6 +76,7 @@ public string MultiLine
5476

5577

5678
public ICommand ClearMultiLineCommand { get; set; }
79+
public ICommand ResetTransparencyCommand { get; set; }
5780

5881

5982
public MainWindowViewModel()
@@ -65,23 +88,17 @@ public MainWindowViewModel()
6588

6689
private void Init()
6790
{
91+
ResetTransparencyCommand = new DelegateCommand(ResetTransparency);
6892
ClearMultiLineCommand = new DelegateCommand(ClearMultiLine);
6993
ClearMultiLine();
7094
}
7195

7296
private void ClearMultiLine() => this.MultiLine = String.Empty;
73-
97+
private void ResetTransparency() => this.TransparencyValue = 1;
7498

7599

76100
#region Settings
77101

78-
private Settings _settings;
79-
80-
public Settings Settings
81-
{
82-
get { return _settings; }
83-
set { SetProperty(ref _settings, value, () => Settings); }
84-
}
85102

86103

87104
private ObservableCollection<string> _themes;
@@ -132,13 +149,15 @@ private void LoadSettings()
132149
this.Settings = SettingsLogic.GetSettings();
133150
SelectedTheme = Themes.FirstOrDefault(f => f == this.Settings.SelectedThemeName);
134151
SelectedAccent = Accents.FirstOrDefault(f => f == this.Settings.SelectedAccentName);
152+
TransparencyValue = Settings.TransparencyValue;
135153
}
136154

137155

138156
public void SaveSettings()
139157
{
140158
Settings.SelectedAccentName = this.SelectedAccent;
141159
Settings.SelectedThemeName = this.SelectedTheme;
160+
Settings.TransparencyValue = this.TransparencyValue;
142161
SettingsLogic.SaveSettings(this.Settings);
143162
}
144163

QuickNoteWidget/Settings.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ public class Settings
1111
public bool OnTop { get; set; }
1212
public bool DisplayDetails { get; set; }
1313
public bool ShowInTaskbar { get; set; }
14+
public double TransparencyValue { get; set; }
1415
}
1516

1617
public static class SettingsLogic
@@ -66,6 +67,7 @@ private static Settings DeserializeFromFile()
6667
OnTop = false,
6768
DisplayDetails = false,
6869
ShowInTaskbar = false,
70+
TransparencyValue = 0.3,
6971
};
7072

7173

0 commit comments

Comments
 (0)