Skip to content

Commit

Permalink
Added Drag and drop section (#413)
Browse files Browse the repository at this point in the history
  • Loading branch information
Leo-Peyronnet committed May 5, 2024
1 parent 4e69175 commit 133703a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
23 changes: 23 additions & 0 deletions ColorPicker/Pages/ImageExtractorPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,29 @@
Visibility="Collapsed">
<StackPanel x:Name="ImageDisplayer" Orientation="Horizontal" />
</ScrollViewer>
<Border
x:Name="DragZone"
Grid.Row="2"
Margin="10"
Padding="10"
AllowDrop="True"
BorderBrush="{DynamicResource LightAccentColor}"
BorderThickness="1"
CornerRadius="5"
Drop="DragZone_Drop"
MouseLeftButtonUp="DragZone_MouseLeftButtonUp">
<StackPanel>
<TextBlock
FontFamily="..\Fonts\#FluentSystemIcons-Regular"
FontSize="36"
Text="&#xF9AE;"
TextAlignment="Center" />
<TextBlock
FontWeight="Bold"
Text="{x:Static lang:Resources.DragImagesHere}"
TextAlignment="Center" />
</StackPanel>
</Border>
<Button
x:Name="ExtractBtn"
Grid.Row="3"
Expand Down
26 changes: 26 additions & 0 deletions ColorPicker/Pages/ImageExtractorPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ MIT License
using ColorPicker.UserControls;
using Microsoft.Win32;
using Synethia;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
Expand Down Expand Up @@ -68,6 +69,7 @@ private void LoadImageUI()
ImageScrollViewer.Visibility = ImageDisplayer.Children.Count == 0 ? Visibility.Collapsed : Visibility.Visible;
ColorPlaceholder.Visibility = ImageDisplayer.Children.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
if (ImageDisplayer.Children.Count == 0) ColorDisplayerBorder.Visibility = Visibility.Collapsed;
DragZone.Visibility = ImageDisplayer.Children.Count == 0 ? Visibility.Visible : Visibility.Collapsed;
}

private void BrowseBtn_Click(object sender, RoutedEventArgs e)
Expand Down Expand Up @@ -225,4 +227,28 @@ private void SortBtn_Click(object sender, RoutedEventArgs e)
Colors = ascending ? Colors.OrderBy(x => x.Value).ToDictionary(x => x.Key, x => x.Value) : Colors.OrderByDescending(x => x.Value).ToDictionary(x => x.Key, x => x.Value);
LoadColorDisplayer(Colors);
}

private void DragZone_Drop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);

foreach (string file in files)
{
string extension = Path.GetExtension(file).ToLower();

if (extension == ".jpg" || extension == ".png" || extension == ".jpeg" || extension == ".bmp" || extension == ".gif" || extension == ".ico")
{
filePaths.Add(file);
}
}
LoadImageUI();
}
}

private void DragZone_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
BrowseBtn_Click(sender, e);
}
}

0 comments on commit 133703a

Please sign in to comment.