From 93c92dfce1d5ee4919c0a6f6dd8131cd519b77e5 Mon Sep 17 00:00:00 2001 From: Pawel Krzywdzinski Date: Tue, 9 Jan 2024 17:20:22 +0100 Subject: [PATCH] doc update --- doc/userdefinedmethods.md | 54 +++++++++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/doc/userdefinedmethods.md b/doc/userdefinedmethods.md index ea52948..c7ab713 100644 --- a/doc/userdefinedmethods.md +++ b/doc/userdefinedmethods.md @@ -1,39 +1,73 @@ # User defined extension methods -In __CodeMarkup.Maui__, you can create your own extension methods by defining a static method within a static class. +In `Sharp.UI`, you can create your own extension methods by defining a static method within a static class. -Here's an example of extension methods that set an entry font size: +Here's an example of extension methods that set a label font size: ```cs public static T FontSize(this T self, double fontSize) - where T : Microsoft.Maui.Controls.Entry + where T : Microsoft.Maui.Controls.Label { - self.SetValue(Microsoft.Maui.Controls.Entry.FontSizeProperty, fontSize); + self.SetValue(Microsoft.Maui.Controls.Label.FontSizeProperty, fontSize); return self; } public static T FontSize(this T self, Func, IPropertyBuilder> configure) - where T : Microsoft.Maui.Controls.Entry + where T : Microsoft.Maui.Controls.Label { - var context = new PropertyContext(self, Microsoft.Maui.Controls.Entry.FontSizeProperty); + var context = new PropertyContext(self, Microsoft.Maui.Controls.Label.FontSizeProperty); configure(context).Build(); return self; } public static SettersContext FontSize(this SettersContext self, double fontSize) - where T : Microsoft.Maui.Controls.Entry + where T : Microsoft.Maui.Controls.Label { - self.XamlSetters.Add(new Setter { Property = Microsoft.Maui.Controls.Entry.FontSizeProperty, Value = fontSize }); + self.XamlSetters.Add(new Setter { Property = Microsoft.Maui.Controls.Label.FontSizeProperty, Value = fontSize }); return self; } public static SettersContext FontSize(this SettersContext self, Func, IPropertySettersBuilder> configure) - where T : Microsoft.Maui.Controls.Entry + where T : Microsoft.Maui.Controls.Label { - var context = new PropertySettersContext(self.XamlSetters, Microsoft.Maui.Controls.Entry.FontSizeProperty); + var context = new PropertySettersContext(self.XamlSetters, Microsoft.Maui.Controls.Label.FontSizeProperty); configure(context).Build(); return self; } + +public static Task AnimateFontSizeTo(this T self, double value, uint length = 250, Easing? easing = null) + where T : Microsoft.Maui.Controls.Label +{ + double fromValue = self.FontSize; + var transform = (double t) => Transformations.DoubleTransform(fromValue, value, t); + var callback = (double actValue) => { self.FontSize = actValue; }; + return Transformations.AnimateAsync(self, "AnimateFontSizeTo", transform, callback, length, easing); +} ``` + +it allows you the following usage: + +```cs +new Label().FontSize(28) +``` + +or: + +```cs +new Label().FontSize(e => e.Path("MyFontSize").Source(myModel)) +new Label().FontSize(e => e.OnPhone(30).OnTablet(50).Default(40)) +``` + +or use it in a style context: + +```cs +new Style