Browse Source

feat(ControlCatalog): Add sample how binding DataGridColumn Width

Giuseppe Lippolis 2 years ago
parent
commit
a5f615d783

+ 31 - 0
samples/ControlCatalog/Models/GDPdLengthConverter.cs

@@ -0,0 +1,31 @@
+using System;
+using System.Globalization;
+using Avalonia.Data.Converters;
+
+namespace ControlCatalog.Models;
+
+internal class GDPdLengthConverter : IValueConverter
+{
+    public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
+    {
+        if (value is double d)
+        {
+            return new Avalonia.Controls.DataGridLength(d,Avalonia.Controls.DataGridLengthUnitType.Pixel,d,d);
+        }
+        else if (value is decimal d2)
+        {
+            var dv =System.Convert.ToDouble(d2);
+            return new Avalonia.Controls.DataGridLength(dv, Avalonia.Controls.DataGridLengthUnitType.Pixel, dv, dv);
+        }
+        return value;
+    }
+
+    public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
+    {
+        if (value is Avalonia.Controls.DataGridLength width)
+        {
+            return System.Convert.ToDecimal(width.DisplayValue);
+        }
+        return value;
+    }
+}

File diff suppressed because it is too large
+ 3 - 0
samples/ControlCatalog/Pages/DataGridPage.xaml


Some files were not shown because too many files changed in this diff