Browse Source

Fixed Layout Issues in MobileToolGrid

Frank van den Bos 1 year ago
parent
commit
1743012703

+ 6 - 4
InABox.Mobile/InABox.Mobile.Shared/Components/MobileToolGrid/MobileToolGrid.xaml.cs

@@ -55,13 +55,13 @@ namespace InABox.Mobile
                 if (args.OldItems != null)
                 {
                     foreach (var item in args.OldItems?.OfType<MobileToolItem>())
-                        item.Changed -= ItemChanged;
+                        item.VisibleChanged -= ItemChanged;
                 }
 
                 if (args.NewItems != null)
                 {
                     foreach (var item in args.NewItems.OfType<MobileToolItem>())
-                        item.Changed += ItemChanged;
+                        item.VisibleChanged += ItemChanged;
                 }
 
                 Refresh();
@@ -80,8 +80,10 @@ namespace InABox.Mobile
             VisibleItems.AddRange(Items.Where(x => x.IsVisible).ToArray());
             int iRow = 0;
             int iCol = 0;
+            bool bDirty = false;
             foreach (var item in VisibleItems)
             {
+                bDirty = iRow != item.Row || iCol != item.Column;
                 item.Row = iRow;
                 item.Column = iCol;
                 iCol++;
@@ -91,7 +93,8 @@ namespace InABox.Mobile
                     iCol = 0;
                 }
             }
-            LayoutChanged?.Invoke(this,new ToolGridLayoutChangedEventArgs(iRow,Columns));
+            if (bDirty)
+                LayoutChanged?.Invoke(this,new ToolGridLayoutChangedEventArgs(iRow,Columns));
         }
 
         public Color BackgroundColor { get; set; }
@@ -185,7 +188,6 @@ namespace InABox.Mobile
                 _flexgrid.ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Star});
             BindableLayout.SetItemsSource(_flexgrid, null);
             BindableLayout.SetItemsSource(_flexgrid, _viewModel.VisibleItems);
-
         }
         
     }

+ 31 - 17
InABox.Mobile/InABox.Mobile.Shared/Components/MobileToolGrid/MobileToolItem.cs

@@ -26,15 +26,16 @@ namespace InABox.Mobile
         public static readonly BindableProperty TextProperty = BindableProperty.Create(nameof(Text), typeof(string), typeof(MobileToolItem), "");
         public string Text
         {
-            get { return (string)GetValue(TextProperty); }
-            set { SetValue(TextProperty, value); }
+            get => (string)GetValue(TextProperty);
+            set => SetValue(TextProperty, value);
         }
 
         public static readonly BindableProperty ImageProperty = BindableProperty.Create(nameof(Image), typeof(ImageSource), typeof(MobileToolItem), null);
         public ImageSource Image
         {
-            get { return (ImageSource)GetValue(ImageProperty); }
-            set { SetValue(ImageProperty, value); }
+            get => (ImageSource)GetValue(ImageProperty); 
+            set =>SetValue(ImageProperty, value);
+            
         }
         
         public static readonly BindableProperty AlertProperty = BindableProperty.Create(
@@ -44,8 +45,9 @@ namespace InABox.Mobile
             null);
         public string Alert
         {
-            get { return (string)GetValue(AlertProperty); }
-            set { 
+            get => (string)GetValue(AlertProperty);
+            set
+            {
                 SetValue(AlertProperty, value);
                 OnPropertyChanged(nameof(AlertVisible));
             }
@@ -74,7 +76,7 @@ namespace InABox.Mobile
         public Color TextColor
         {
             get => (Color)GetValue(TextColorProperty);
-            set => SetValue(TextColorProperty, value);
+            set => SetValue(TextColorProperty, value); 
         }
                 
         public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(MobileToolItem), true);
@@ -83,8 +85,10 @@ namespace InABox.Mobile
             get { return (bool)GetValue(IsEnabledProperty); }
             set
             {
+                var old = (bool)GetValue(IsEnabledProperty);
                 SetValue(IsEnabledProperty, value);
-                DoChanged();
+                if (old != value)
+                    DoEnabledChanged();
             }
         }
         
@@ -95,8 +99,10 @@ namespace InABox.Mobile
             get { return (bool)GetValue(IsVisibleProperty); }
             set
             {
+                var old = (bool)GetValue(IsVisibleProperty);
                 SetValue(IsVisibleProperty, value);
-                DoChanged();
+                if (old != value)
+                    DoVisibleChanged();
             }
         }
         
@@ -104,17 +110,18 @@ namespace InABox.Mobile
         public static readonly BindableProperty RowProperty = BindableProperty.Create(nameof(Row), typeof(Int32), typeof(MobileToolItem));
         public Int32 Row
         {
-            get { return (Int32)GetValue(RowProperty); }
-            set { SetValue(RowProperty, value); }
+            get => (Int32)GetValue(RowProperty);
+            set => SetValue(RowProperty, value);
         }
         
         public static readonly BindableProperty ColumnProperty = BindableProperty.Create(nameof(Column), typeof(Int32), typeof(MobileToolItem));
+
         public Int32 Column
         {
-            get { return (Int32)GetValue(ColumnProperty); }
-            set { SetValue(ColumnProperty, value); }
+            get => (Int32)GetValue(ColumnProperty);
+            set => SetValue(ColumnProperty, value);
         }
-        
+
         public int ID { get; set; }
         
         public event EventHandler Clicked;
@@ -125,11 +132,18 @@ namespace InABox.Mobile
         }
         
                 
-        public event EventHandler Changed;
+        public event EventHandler VisibleChanged;
+
+        public void DoVisibleChanged()
+        {
+            VisibleChanged?.Invoke(this, EventArgs.Empty);
+        }
+        
+        public event EventHandler EnabledChanged;
 
-        public void DoChanged()
+        public void DoEnabledChanged()
         {
-            Changed?.Invoke(this, EventArgs.Empty);
+            EnabledChanged?.Invoke(this, EventArgs.Empty);
         }