Selaa lähdekoodia

Add option to keep window right-aligned

(Mostly)
Closes #23 and Closes #21
Daniel Chalmers 2 vuotta sitten
vanhempi
sitoutus
a4ae49d815

+ 2 - 1
DesktopClock/MainWindow.xaml

@@ -21,7 +21,8 @@
         MouseDoubleClick="Window_MouseDoubleClick"
         MouseWheel="Window_MouseWheel"
         SourceInitialized="Window_SourceInitialized"
-        Closing="Window_Closing">
+        Closing="Window_Closing"
+		SizeChanged="Window_SizeChanged">
 	<Window.Resources>
 		<ContextMenu x:Key="MainContextMenu" x:Shared="False">
 			<MenuItem Command="{Binding CopyToClipboardCommand}" Header="_Copy" />

+ 9 - 0
DesktopClock/MainWindow.xaml.cs

@@ -272,4 +272,13 @@ public partial class MainWindow : Window
 
         Settings.Default.Dispose();
     }
+
+    private void Window_SizeChanged(object sender, SizeChangedEventArgs e)
+    {
+        if (e.WidthChanged && Settings.Default.RightAligned)
+        {
+            var previousRight = Left + e.PreviousSize.Width;
+            Left = previousRight - ActualWidth;
+        }
+    }
 }

+ 1 - 0
DesktopClock/Properties/Settings.cs

@@ -67,6 +67,7 @@ public sealed class Settings : INotifyPropertyChanged, IDisposable
     public int Height { get; set; } = 48;
     public bool RunOnStartup { get; set; } = false;
     public bool DragToMove { get; set; } = true;
+    public bool RightAligned { get; set; } = false;
     public WindowPlacement Placement { get; set; }
 
     [JsonIgnore]