Explorar el Código

Fixed refresh in design mode of dashboards, and added PreviewHeight

Kenric Nugteren hace 4 meses
padre
commit
be5d3baa68

+ 24 - 14
inabox.wpf/Dashboard/Editor/DynamicDashboardEditor.xaml.cs

@@ -86,11 +86,15 @@ public partial class DynamicDashboardEditor : UserControl, INotifyPropertyChange
         if(dashboard.DataPresenter is not null)
         {
             _selectedPresentationType = dashboard.DataPresenter.GetType();
-            SetProperties(dashboard.DataPresenter.Properties, _selectedPresentationType);
         }
 
         InitializeComponent();
 
+        if(dashboard.DataPresenter is not null)
+        {
+            SetProperties(dashboard.DataPresenter.Properties, _selectedPresentationType!);
+        }
+
         PresentationTypes = DynamicDashboardUtils.GetPresenterTypes()
             .Select(x => new Tuple<string, Type>(x.GetCaption(), x))
             .ToArray();
@@ -105,27 +109,33 @@ public partial class DynamicDashboardEditor : UserControl, INotifyPropertyChange
         _presenter.DataComponent = DataComponent;
 
         PresentationEditorControl.Content = _presenter.Setup();
+        PresentationEditorControl.Height = _presenter.PreviewHeight;
+        RefreshData();
     }
 
     private void SelectData_Click(object sender, RoutedEventArgs e)
     {
         if (DynamicDashboardDataEditor.Execute(DataComponent))
         {
-            if(_presenter is not null)
+            RefreshData();
+        }
+    }
+    private void RefreshData()
+    {
+        if(_presenter is not null)
+        {
+            _presenter.DataComponent = DataComponent;
+            DataComponent.RunQueryAsync(100).ContinueWith(data =>
             {
-                _presenter.DataComponent = DataComponent;
-                DataComponent.RunQueryAsync(100).ContinueWith(data =>
+                if(data.Exception is not null)
                 {
-                    if(data.Exception is not null)
-                    {
-                        MessageWindow.ShowError("Error loading data.", data.Exception);
-                    }
-                    else
-                    {
-                        _presenter.Refresh(data.Result);
-                    }
-                }, TaskScheduler.FromCurrentSynchronizationContext());
-            }
+                    MessageWindow.ShowError("Error loading data.", data.Exception);
+                }
+                else
+                {
+                    _presenter.Refresh(data.Result);
+                }
+            }, TaskScheduler.FromCurrentSynchronizationContext());
         }
     }
 

+ 3 - 4
inabox.wpf/Dashboard/Presenters/DynamicDashboardGridPresenter.cs

@@ -40,11 +40,10 @@ public class DynamicDashboardGridPresenter : IDynamicDashboardDataPresenter<Dyna
         }
     }
 
+    public int PreviewHeight => 300;
+
     private IDynamicDashboardGridPresenterGrid? Grid;
-    private ContentControl Content = new()
-    {
-        Height = 300
-    };
+    private readonly ContentControl Content = new();
 
     private DynamicDashboardData? _data;
 

+ 5 - 0
inabox.wpf/Dashboard/Presenters/IDynamicDashboardDataPresenter.cs

@@ -11,6 +11,11 @@ namespace InABox.Wpf.Dashboard;
 
 public interface IDynamicDashboardDataPresenter
 {
+    /// <summary>
+    /// The desired height for this presenter while previewing in design mode.
+    /// </summary>
+    int PreviewHeight { get; }
+
     object Properties { get; set; }
 
     /// <summary>