diff --git a/Helpers/StackPanelHelper.cs b/Helpers/StackPanelHelper.cs new file mode 100644 index 0000000..2c19d65 --- /dev/null +++ b/Helpers/StackPanelHelper.cs @@ -0,0 +1,83 @@ +using System.Windows; +using System.Windows.Controls; + +namespace PrettyScreenSHOT.Helpers +{ + /// + /// Helper class that adds Spacing support to StackPanel (WPF compatibility) + /// + public static class StackPanelHelper + { + /// + /// Attached property for adding spacing between StackPanel children + /// + public static readonly DependencyProperty SpacingProperty = + DependencyProperty.RegisterAttached( + "Spacing", + typeof(double), + typeof(StackPanelHelper), + new PropertyMetadata(0.0, OnSpacingChanged)); + + public static double GetSpacing(DependencyObject obj) + { + return (double)obj.GetValue(SpacingProperty); + } + + public static void SetSpacing(DependencyObject obj, double value) + { + obj.SetValue(SpacingProperty, value); + } + + private static void OnSpacingChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is StackPanel stackPanel) + { + stackPanel.Loaded -= StackPanel_Loaded; + stackPanel.Loaded += StackPanel_Loaded; + + if (stackPanel.IsLoaded) + { + ApplySpacing(stackPanel); + } + } + } + + private static void StackPanel_Loaded(object sender, RoutedEventArgs e) + { + if (sender is StackPanel stackPanel) + { + ApplySpacing(stackPanel); + } + } + + private static void ApplySpacing(StackPanel stackPanel) + { + var spacing = GetSpacing(stackPanel); + var isHorizontal = stackPanel.Orientation == Orientation.Horizontal; + + for (int i = 0; i < stackPanel.Children.Count; i++) + { + if (stackPanel.Children[i] is FrameworkElement element) + { + if (i == 0) + { + // First element - no spacing + element.Margin = new Thickness(0); + } + else + { + // Add spacing to the left (horizontal) or top (vertical) + if (isHorizontal) + { + element.Margin = new Thickness(spacing, 0, 0, 0); + } + else + { + element.Margin = new Thickness(0, spacing, 0, 0); + } + } + } + } + } + } +} diff --git a/Views/Dialogs/SaveScreenshotDialog.xaml b/Views/Dialogs/SaveScreenshotDialog.xaml index 26659b9..83db03e 100644 --- a/Views/Dialogs/SaveScreenshotDialog.xaml +++ b/Views/Dialogs/SaveScreenshotDialog.xaml @@ -2,6 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" + xmlns:helpers="clr-namespace:PrettyScreenSHOT.Helpers" Title="Save Screenshot" Height="450" Width="520" @@ -33,9 +34,9 @@ - + - + @@ -44,7 +45,7 @@ - + @@ -54,7 +55,7 @@ - + @@ -70,7 +71,7 @@ - + + helpers:StackPanelHelper.Spacing="8"> @@ -85,7 +86,7 @@ - + + helpers:StackPanelHelper.Spacing="8"> - + + helpers:StackPanelHelper.Spacing="4"> @@ -135,7 +136,7 @@ + helpers:StackPanelHelper.Spacing="8"> + Icon="pack://application:,,,/app.ico"/> - + @@ -90,7 +90,7 @@ - + @@ -116,7 +116,7 @@ - + @@ -141,7 +141,7 @@ - + - + @@ -44,20 +45,20 @@ - + - + - + @@ -82,9 +83,9 @@ - + - + - + - + - + - + - + @@ -186,7 +187,7 @@ - + - + @@ -226,7 +227,7 @@ - + @@ -249,7 +250,7 @@ - + - + @@ -88,11 +89,11 @@ - + + helpers:StackPanelHelper.Spacing="8"> + helpers:StackPanelHelper.Spacing="8"> - + diff --git a/Views/Windows/UpdateWindow.xaml b/Views/Windows/UpdateWindow.xaml index 83a2601..5da8164 100644 --- a/Views/Windows/UpdateWindow.xaml +++ b/Views/Windows/UpdateWindow.xaml @@ -2,6 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" + xmlns:helpers="clr-namespace:PrettyScreenSHOT.Helpers" Title="Update Available" Height="550" Width="620" @@ -33,7 +34,7 @@ - + - + @@ -92,7 +93,7 @@ - + @@ -116,7 +117,7 @@ - + - + - +