Skip to content

Commit 8111cdf

Browse files
committed
Added Window Resize Functionality to UI.
1 parent 3f697df commit 8111cdf

File tree

2 files changed

+67
-11
lines changed

2 files changed

+67
-11
lines changed

QuickNoteWidget/MainWindow.xaml

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,16 @@
1212
KeyDown="Window_KeyDown"
1313
WindowStyle="None"
1414
Title="MainWindow"
15-
Height="350"
16-
Width="600"
15+
Height="{Binding WindowHeight, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
16+
Width="{Binding WindowWidht, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
1717
MinHeight="200"
1818
MinWidth="200"
1919
ResizeMode="CanResize"
2020
Topmost="{Binding OnTop}"
2121
ShowInTaskbar="{Binding ShowInTaskbar}"
2222
AllowsTransparency="True"
2323
Opacity="{Binding TransparencyValue, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
24-
ContextMenu="{DynamicResource contextMenu}"
25-
>
24+
ContextMenu="{DynamicResource contextMenu}">
2625
<Window.Resources>
2726
<converter:AccentToColorConverter x:Key="AccentToColorConverter" />
2827
<converter:StringToFontStyleConverter x:Key="fontStyle" />
@@ -31,7 +30,7 @@
3130
<converter:BoolToVisibilityCollapsedConverter x:Key="BoolToVisibilityCollapsedConverter" />
3231
<Style TargetType="TextBlock">
3332
<Setter Property="Foreground"
34-
Value="{Binding SelectedAccent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource AccentToColorConverter}}" />
33+
Value="{Binding SelectedAccent, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource AccentToColorConverter}}" />
3534
</Style>
3635
<ContextMenu x:Key="contextMenu">
3736
<MenuItem Header="Select All (Ctrl + A)"
@@ -81,7 +80,7 @@
8180
Margin="5,0,5,0"
8281
Grid.Column="1"
8382
Grid.Row="1" />
84-
<TextBlock Text="Font: "
83+
<TextBlock Text="Font: "
8584
Grid.Row="2"
8685
VerticalAlignment="Center" />
8786
<ComboBox Width="140"
@@ -103,6 +102,9 @@
103102
</MenuItem>
104103
<MenuItem Header="Reset Settings"
105104
Command="{Binding ResetViewCommand}" />
105+
<CheckBox Content="Display Window Resize"
106+
ToolTip="Alt + H(eight) or Alt + W(idth) with Mouse Scrolling for more precise resizing."
107+
IsChecked="{Binding IsWindowResizeBarVisible, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" />
106108
<MenuItem Header="Info"
107109
Click="Info_Click" />
108110
</ContextMenu>
@@ -144,6 +146,22 @@
144146
</StatusBarItem>
145147
<Separator Margin="10,0,10,0"
146148
HorizontalAlignment="Left" />
149+
<StatusBarItem Visibility="{Binding IsWindowResizeBarVisible, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay, Converter={StaticResource BoolToVisibilityCollapsedConverter}}">
150+
<StackPanel Orientation="Horizontal"
151+
ToolTip="Alt + H(eight) or Alt + W(idth) with Mouse Scrolling for more precise resizing.">
152+
<TextBlock Text="Window Size"
153+
VerticalAlignment="Center"
154+
Margin="0,0,5,0" />
155+
<StackPanel Orientation="Horizontal">
156+
<Button Content="-"
157+
Command="{Binding ReduceWindowSizeCommand}"
158+
Width="20" />
159+
<Button Content="+"
160+
Command="{Binding IncreaseWindowSizeCommand}"
161+
Width="20" />
162+
</StackPanel>
163+
</StackPanel>
164+
</StatusBarItem>
147165
</StatusBar>
148166
<avalonedit:TextEditor x:Name="tbxMultiLine"
149167
DockPanel.Dock="Top"
@@ -161,7 +179,6 @@
161179
FontFamily="{Binding CurrentFont, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
162180
PreviewMouseWheel="tbxMultiLine_PreviewMouseWheel" />
163181
</DockPanel>
164-
165182
<tb:TaskbarIcon IconSource=".\Clipboard.ico"
166183
x:Name="TaskbarIcon"
167184
Grid.RowSpan="2"

QuickNoteWidget/MainWindowViewModel.cs

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,25 @@ public class MainWindowViewModel : ViewModelBase
3838
private bool _showintaskbar;
3939
private bool _displaydetails;
4040
private string _currentfont;
41+
private int _windowHeight;
42+
private int _windowWidht;
43+
private bool _isWindowResizeBarVisible;
4144

42-
45+
public bool IsWindowResizeBarVisible
46+
{
47+
get { return _isWindowResizeBarVisible; }
48+
set { SetProperty(ref _isWindowResizeBarVisible, value, () => IsWindowResizeBarVisible); }
49+
}
50+
public int WindowWidht
51+
{
52+
get { return _windowWidht; }
53+
set { SetProperty(ref _windowWidht, value, () => WindowWidht); }
54+
}
55+
public int WindowHeight
56+
{
57+
get { return _windowHeight; }
58+
set { SetProperty(ref _windowHeight, value, () => WindowHeight); }
59+
}
4360
public string CurrentFont
4461
{
4562
get { return _currentfont; }
@@ -140,7 +157,10 @@ public string MultiLine
140157

141158

142159
public Settings Settings { get; set; }
160+
143161
public ICommand ResetViewCommand { get; set; }
162+
public ICommand ReduceWindowSizeCommand { get; set; }
163+
public ICommand IncreaseWindowSizeCommand { get; set; }
144164

145165

146166

@@ -150,6 +170,8 @@ public MainWindowViewModel()
150170
LoadSettings(SettingsLoadLocations.FromFile);
151171
InitViewModel();
152172
}
173+
174+
153175
private void LoadAvailableThemesAndAccents()
154176
{
155177
Themes = new ObservableCollection<string>() { ThemeManager.BaseColorLight, ThemeManager.BaseColorDark };
@@ -188,8 +210,28 @@ private void UpdateProperties()
188210

189211
private void InitViewModel()
190212
{
213+
WindowHeight = 350;
214+
WindowWidht = 650;
215+
IsWindowResizeBarVisible = true;
191216
Fonts = new ObservableCollection<string>(LoadInstalledFonts());
192217
ResetViewCommand = new DelegateCommand(ResetView);
218+
ReduceWindowSizeCommand = new DelegateCommand(ReduceWindowSize);
219+
IncreaseWindowSizeCommand = new DelegateCommand(IncreaseWindowSize);
220+
}
221+
222+
private void ReduceWindowSize()
223+
{
224+
if(this.WindowHeight > 100)
225+
this.WindowHeight -= 15;
226+
if(IsWindowResizeBarVisible)
227+
if(this.WindowWidht > 500)
228+
this.WindowWidht -= 15;
229+
}
230+
231+
private void IncreaseWindowSize()
232+
{
233+
this.WindowHeight += 15;
234+
this.WindowWidht += 15;
193235
}
194236

195237
private IEnumerable<string> LoadInstalledFonts()
@@ -213,9 +255,6 @@ private void UpdateFontColorOnThemeSelectionChanged()
213255
MultiLineTextForegroundColor = LIGHT_GRAY;
214256
}
215257

216-
217-
218-
219258
public void SaveSettingsOnClose()
220259
{
221260
Settings.SelectedAccentName = this.SelectedAccent;

0 commit comments

Comments
 (0)