Kaynağa Gözat

Fixed some Drag / Drop Issues
Added properties to Hide/Show and Highlight Editor Forms Buttons

frogsoftware 1 yıl önce
ebeveyn
işleme
8cfeba6b04

+ 2 - 19
inabox.wpf/DynamicGrid/DynamicEditorForm/EmbeddedDynamicEditorForm.xaml

@@ -6,19 +6,6 @@
              xmlns:local="clr-namespace:InABox.DynamicGrid"
              mc:Ignorable="d" 
              d:DesignHeight="450" d:DesignWidth="800" >
-    <UserControl.Resources>
-        <Style TargetType="{x:Type Button}" x:Key="ButtonStyle">
-            <Style.Triggers>
-                <DataTrigger Binding="{Binding IsEnabled}" Value="True">
-                    <Setter Property="Foreground" Value="Yellow" />
-                </DataTrigger>
-                <DataTrigger Binding="{Binding IsEnabled}" Value="False">
-                    <Setter Property="Foreground" Value="Blue" />
-                </DataTrigger>
-            </Style.Triggers>
-        </Style>
-    </UserControl.Resources>
-    
     <Grid x:Name="LayoutGrid">
 
         <Grid.ColumnDefinitions>
@@ -69,12 +56,10 @@
             Grid.Column="1" 
             Margin="0,5,5,5" 
             Click="OKButton_Click" 
-            IsEnabled="False"
             BorderBrush="DarkGreen"
             Background="LimeGreen"
             Foreground="White"
-            FontWeight="Bold"
-            Style="{StaticResource ButtonStyle}"/>
+            FontWeight="Bold"/>
         
         <Button 
             x:Name="CancelButton" 
@@ -82,13 +67,11 @@
             Grid.Row="1" 
             Grid.Column="2" 
             Margin="0,5,5,5" 
-            IsEnabled="False"
             Click="CancelButton_Click"
             BorderBrush="Firebrick"
             Background="Red"
             Foreground="White"
-            FontWeight="Bold"
-            Style="{StaticResource ButtonStyle}"/>
+            FontWeight="Bold"/>
         
     </Grid>
 </UserControl>

+ 48 - 16
inabox.wpf/DynamicGrid/DynamicEditorForm/EmbeddedDynamicEditorForm.xaml.cs

@@ -4,18 +4,10 @@ using System.Collections.Generic;
 using System.ComponentModel;
 using System.Diagnostics.CodeAnalysis;
 using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
 using System.Windows;
 using System.Windows.Controls;
-using System.Windows.Data;
-using System.Windows.Documents;
-using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
-using System.Windows.Navigation;
-using System.Windows.Shapes;
-using Document = InABox.Core.Document;
 
 namespace InABox.DynamicGrid
 {
@@ -35,8 +27,8 @@ namespace InABox.DynamicGrid
 
         public void DoChanged()
         {
-            OKButton.IsEnabled = true;
-            CancelButton.IsEnabled = true;
+            //OKButton.IsEnabled = true;
+            //CancelButton.IsEnabled = true;
             OnChanged?.Invoke(this, EventArgs.Empty);
         }
 
@@ -66,11 +58,51 @@ namespace InABox.DynamicGrid
             get => Editor.ReadOnly;
             set
             {
-                OKButton.IsEnabled = !value && CancelButton.IsEnabled;
+                OKButton.IsEnabled = !value;
+                CancelButton.IsEnabled = !value;
                 Editor.ReadOnly = value;
             }
         }
-        
+
+        private bool _hideButtons = false;
+
+        public bool HideButtons
+        {
+            get => _hideButtons;
+            set
+            {
+                _hideButtons = value;
+                OKButton.Visibility = value ? Visibility.Collapsed : Visibility.Visible;
+                CancelButton.Visibility = value ? Visibility.Collapsed : Visibility.Visible;
+
+            }
+        }
+
+        private bool _highlightButtons = false;
+        public bool HighlightButtons
+        {
+            get => _highlightButtons;
+            set
+            {
+                _highlightButtons = value;
+                UpdateButtonHighlight(OKButton, Colors.DarkGreen, Colors.LimeGreen, Colors.White);
+                UpdateButtonHighlight(CancelButton, Colors.Firebrick, Colors.Red, Colors.White);
+            }
+        }
+
+        private void UpdateButtonHighlight(Button button, Color border, Color background, Color foreground)
+        {
+            button.BorderBrush = _highlightButtons
+                ? new SolidColorBrush(border)
+                : new SolidColorBrush(Colors.Gray);
+            button.Background = _highlightButtons
+                ? new SolidColorBrush(background)
+                : new SolidColorBrush(Colors.Gainsboro);
+            button.Foreground = _highlightButtons
+                ? new SolidColorBrush(foreground)
+                : new SolidColorBrush(Colors.Black);
+        }
+
         public static readonly DependencyProperty ButtonsVisibleProperty =
             DependencyProperty.Register(
                 nameof(ButtonsVisible), 
@@ -283,8 +315,8 @@ namespace InABox.DynamicGrid
                 return;
             }
             OnOK?.Invoke();
-            OKButton.IsEnabled = false;
-            CancelButton.IsEnabled = false;
+            //OKButton.IsEnabled = false;
+            //CancelButton.IsEnabled = false;
 
             // Don't Commit the changes here, because we want to refer back to thos changes when we save the item
             // to trigger specific processes in the database
@@ -298,8 +330,8 @@ namespace InABox.DynamicGrid
                 item.CancelChanges();
 
             OnCancel?.Invoke();
-            OKButton.IsEnabled = false;
-            CancelButton.IsEnabled = false;
+            //OKButton.IsEnabled = false;
+            //CancelButton.IsEnabled = false;
             //Close();
         }
 

+ 51 - 25
inabox.wpf/DynamicGrid/DynamicGrid.cs

@@ -495,7 +495,20 @@ namespace InABox.DynamicGrid
             DataGrid.ColumnSizer = GridLengthUnitType.AutoLastColumnFill;
             DataGrid.SelectionForegroundBrush = BaseDynamicGrid.SelectionForeground;
             DataGrid.RowSelectionBrush = BaseDynamicGrid.SelectionBackground;
-
+            
+            DataGrid.AllowDraggingRows = false;
+            DataGrid.Drop += DataGrid_Drop;
+            DataGrid.RowDragDropTemplate = TemplateGenerator.CreateDataTemplate(() =>
+            {
+                var border = new Border();
+                border.Width = 100;
+                border.Height = 100;
+                border.BorderBrush = new SolidColorBrush(Colors.Firebrick);
+                border.Background = new SolidColorBrush(Colors.Red);
+                border.CornerRadius = new CornerRadius(5);
+                return border;
+            });
+            
             DataGrid.CurrentCellBorderThickness = new Thickness(0);
             DataGrid.AllowFiltering = false;
             DataGrid.EnableDataVirtualization = true;
@@ -781,25 +794,23 @@ namespace InABox.DynamicGrid
 
             if (Options.Contains(DynamicGridOption.DragSource))
             {
-                DataGrid.AllowDraggingRows = true;
-                DataGrid.RowDragDropController.DragStart += RowDragDropController_DragStart;
-            }
-            else if (DataGrid.AllowDraggingRows)
-            {
-                DataGrid.AllowDraggingRows = false;
-                DataGrid.RowDragDropController.DragStart -= RowDragDropController_DragStart;
-            }
-            if (Options.Contains(DynamicGridOption.DragTarget) && !DataGrid.AllowDrop)
-            {
-                DataGrid.Drop += DataGrid_Drop;
-                DataGrid.AllowDrop = true;
+                if (!DataGrid.AllowDraggingRows)
+                {
+                    DataGrid.AllowDraggingRows = true;
+                    DataGrid.RowDragDropController.DragStart += RowDragDropController_DragStart;
+                }
             }
-            else if (DataGrid.AllowDrop)
+            else
             {
-                DataGrid.Drop -= DataGrid_Drop;
-                DataGrid.AllowDrop = false;
+                if (DataGrid.AllowDraggingRows)
+                {
+                    DataGrid.AllowDraggingRows = false;
+                    DataGrid.RowDragDropController.DragStart -= RowDragDropController_DragStart;
+                }
             }
-
+            
+            DataGrid.AllowDrop = Options.Contains(DynamicGridOption.DragTarget);
+            
             DataGrid.SelectionMode = Options.Contains(DynamicGridOption.MultiSelect) ? GridSelectionMode.Extended : GridSelectionMode.Single;
             if (up != null)
                 up.Position = Options.Contains(DynamicGridOption.EditRows) ? DynamicActionColumnPosition.Start : DynamicActionColumnPosition.Hidden;
@@ -3596,15 +3607,25 @@ namespace InABox.DynamicGrid
 
         protected virtual void OnDragEnd(Type entity, CoreTable table)
         {
+            Logger.Send(LogType.Information,"","OnDragEnd");
         }
-
+        
         private void DataGrid_Drop(object sender, DragEventArgs e)
         {
+            Logger.Send(LogType.Information,"","DataGrid_Drop");
+            
+            if (!Options.Contains(DynamicGridOption.DragTarget))
+                return;
+            
+            Logger.Send(LogType.Information,"","DataGrid_Drop::DragTarget==true");
+            
             if (e.Data.GetDataPresent(DragFormat))
             {
+                Logger.Send(LogType.Information,"","DataGrid_Drop::DataPresent==true");
                 var data = e.Data.GetData(DragFormat) as DynamicGridDragFormat;
                 if (data is not null)
-                {
+                { 
+                    Logger.Send(LogType.Information,"","DataGrid_Drop::DragData==DynamicGridDragFormat");
                     var table = new CoreTable();
                     foreach (var column in data.Table.Columns)
                     {
@@ -3624,41 +3645,46 @@ namespace InABox.DynamicGrid
                     }
 
                     OnDragEnd(data.Entity, table);
+                    DoChanged();
+
                 }
             }
         }
 
         protected void DragTable(Type entity, CoreTable table)
         {
+            Logger.Send(LogType.Information,"","DragTable");
             var data = new DataObject();
             data.SetData(DragFormat, new DynamicGridDragFormat(table.ToDataTable(), entity));
-
             DragDrop.DoDragDrop(this, data, DragDropEffects.All);
         }
 
         protected virtual void OnRowsDragStart(CoreRow[] rows)
         {
+            Logger.Send(LogType.Information,"","OnRowsDragStart");
             var table = new CoreTable();
-
             table.LoadColumns(Data.Columns);
             table.LoadRows(rows);
-
             DragTable(typeof(T), table);
         }
 
         private void RowDragDropController_DragStart(object? sender, GridRowDragStartEventArgs e)
         {
+            Logger.Send(LogType.Information,"","RowDragDropController_DragStart");
+            //e.Handled = true;
+            
+            if (!Options.Contains(DynamicGridOption.DragSource))
+                return;
+            
             var rows = new List<CoreRow>();
             foreach (var record in e.DraggingRecords)
             {
                 var rowIndex = DataGrid.ResolveToRowIndex(record);
                 rows.Add(GetRowFromIndex(rowIndex));
             }
-
             var rowArr = rows.ToArray();
             OnRowsDragStart(rowArr);
-
-            e.Handled = true;
+            
         }
 
         #endregion

+ 23 - 0
inabox.wpf/ImageUtils.cs

@@ -874,6 +874,29 @@ namespace InABox.WPF
 
             return frame;
         }
+
+        public static String AsExtension(this ImageFormat format)
+        {
+            if (format.Equals(ImageFormat.Bmp) || format.Equals(ImageFormat.MemoryBmp))
+                return "bmp";
+            if (format.Equals(ImageFormat.Emf))
+                return "emf";
+            if (format.Equals(ImageFormat.Wmf))
+                return "wmf";
+            if (format.Equals(ImageFormat.Gif))
+                return "gif";
+            if (format.Equals(ImageFormat.Jpeg))
+                return "jpeg";
+            if (format.Equals(ImageFormat.Png))
+                return "png";
+            if (format.Equals(ImageFormat.Tiff))
+                return "tiff";
+            if (format.Equals(ImageFormat.Exif))
+                return "exif";
+            if (format.Equals(ImageFormat.Icon))
+                return "ico";
+            return "";
+        }
     }