Procházet zdrojové kódy

Further tweaks for DynamicDocumentGrid

frogsoftware před 1 rokem
rodič
revize
b1d2ba2ae6

+ 22 - 0
inabox.wpf/Converters/DateTimeToVisibilityConverter.cs

@@ -0,0 +1,22 @@
+using System;
+using System.Globalization;
+using System.Windows;
+using InABox.Core;
+
+namespace InABox.WPF;
+
+public class DateTimeToVisibilityConverter : UtilityConverter<DateTime,Visibility>
+{
+    public bool HideIfEmpty { get; set; } = true;
+    
+    public override Visibility Convert(DateTime value)
+    {
+        return value.IsEmpty()
+            ? HideIfEmpty
+                ? Visibility.Collapsed
+                : Visibility.Visible
+            : HideIfEmpty
+                ? Visibility.Visible
+                : Visibility.Collapsed;
+    }
+}

+ 47 - 42
inabox.wpf/DynamicGrid/DynamicDocumentGrid.cs

@@ -23,6 +23,7 @@ using RoslynPad.Editor;
 using Syncfusion.Pdf.Interactive;
 using Syncfusion.Pdf.Parsing;
 using Syncfusion.Pdf;
+using Syncfusion.Windows.Controls.Grid;
 using Syncfusion.Windows.PdfViewer;
 using Border = System.Windows.Controls.Border;
 using Color = System.Windows.Media.Color;
@@ -112,63 +113,53 @@ namespace InABox.DynamicGrid
 
         private FrameworkElement DocumentTemplate()
         {
-            Border border = new Border()
+            Grid grid = new Grid()
             {
-                CornerRadius = new CornerRadius(5),
-                Background = new SolidColorBrush(Colors.WhiteSmoke),
-                BorderBrush = new SolidColorBrush(Colors.Gray),
-                BorderThickness = new Thickness(0.75),
-                Margin = new Thickness(2),
                 Height = 100,
+                RowDefinitions =
+                {
+                    new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
+                    new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) },
+                },
+                ColumnDefinitions =
+                {
+                    new ColumnDefinition() { Width = new GridLength(100) },
+                    new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) },
+                    new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) },
+                },
                 ContextMenu = new ContextMenu()
             };
-            border.ContextMenu.Items.Add(new MenuItem()
+            // grid.SetBinding(
+            //     Grid.BackgroundProperty,
+            //     new Binding("Superceded")
+            //     {
+            //         Converter = new TimeStampToBrushConverter()
+            //         {
+            //             Empty = new SolidColorBrush(Colors.LightYellow),
+            //             Set = new SolidColorBrush(Colors.Silver)
+            //         }
+            //     }
+            // );
+            grid.ContextMenu.Items.Add(new MenuItem()
             {
                 Header = "View Documents",
                 Command = new ActionCommand(ViewDocuments)
             });
-            border.ContextMenu.Items.Add(new MenuItem()
+            grid.ContextMenu.Items.Add(new MenuItem()
             {
                 Header = "Copy To Clipboard",
                 Command = new ActionCommand(CopyDocuments)
             });            
-            border.ContextMenu.Items.Add(new MenuItem()
+            grid.ContextMenu.Items.Add(new MenuItem()
             {
                 Header = "Save Documents",
                 Command = new ActionCommand(SaveDocuments)
             });
             
-            border.SetBinding(
-                Border.BackgroundProperty,
-                new Binding("Superceded")
-                {
-                    Converter = new TimeStampToBrushConverter()
-                    {
-                        Empty = new SolidColorBrush(Colors.LightYellow),
-                        Set = new SolidColorBrush(Colors.Silver)
-                    }
-                }
-            );
-            Grid grid = new Grid()
-            {
-                RowDefinitions =
-                {
-                    new RowDefinition() { Height = new GridLength(1, GridUnitType.Auto) },
-                    new RowDefinition() { Height = new GridLength(1, GridUnitType.Star) },
-                },
-                ColumnDefinitions =
-                {
-                    new ColumnDefinition() { Width = new GridLength(100) },
-                    new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Star) },
-                    new ColumnDefinition() { Width = new GridLength(1, GridUnitType.Auto) },
-                }
-            };
-            border.Child = grid;
-            
             Image thumbnail = new Image()
             {
                 Stretch = Stretch.Uniform,
-                Margin = new Thickness(2,2,5,2),
+                Margin = new Thickness(5,2,5,2),
                 
             };
             
@@ -185,15 +176,29 @@ namespace InABox.DynamicGrid
             thumbnail.SetValue(Grid.RowSpanProperty,2);
             thumbnail.SetValue(Grid.ColumnProperty,0);
             grid.Children.Add(thumbnail);
+
+            var dock = new DockPanel();
+            dock.SetValue(Grid.RowProperty,0);
+            dock.SetValue(Grid.ColumnProperty,1);
+            grid.Children.Add(dock);
+            
+            var superceded = new Label()
+            {
+                FontWeight = FontWeights.Bold,
+                Content = "*** SUPERCEDED ***",
+                Margin = new Thickness(0,0,5,0)
+            };
+            superceded.SetBinding(Label.VisibilityProperty, new Binding("Superceded") { Converter = new DateTimeToVisibilityConverter() });
+            superceded.SetValue(DockPanel.DockProperty, Dock.Left);
+            dock.Children.Add(superceded);
             
             var filename = new Label()
             {
                 FontWeight = FontWeights.Bold
             };
             filename.SetBinding(Label.ContentProperty, new Binding("DocumentLink_FileName"));
-            filename.SetValue(Grid.RowProperty,0);
-            filename.SetValue(Grid.ColumnProperty,1);
-            grid.Children.Add(filename);
+            filename.SetValue(DockPanel.DockProperty, Dock.Left);
+            dock.Children.Add(filename);
 
             var buttons = new StackPanel()
             {
@@ -239,7 +244,7 @@ namespace InABox.DynamicGrid
 
             var print = new Button()
             {
-                Content = new Image() { Source = Wpf.Resources.print.AsBitmapImage() },
+                Content = new Image() { Source = Wpf.Resources.print.AsBitmapImage(), Margin=new Thickness(2) },
                 BorderBrush = new SolidColorBrush(Colors.Transparent),
                 Background = new SolidColorBrush(Colors.Transparent),
                 Height = 32,
@@ -257,7 +262,7 @@ namespace InABox.DynamicGrid
             notes.SetValue(Grid.ColumnSpanProperty,2);
             grid.Children.Add(notes);
             
-            return border;
+            return grid;
         }
 
         private void GetDocuments(Action<Dictionary<string,byte[]>> action)