From 4fe6c677f6aa62db51f31b8251c9123f5c33e470 Mon Sep 17 00:00:00 2001 From: michael-hawker <24302614+michael-hawker@users.noreply.github.com> Date: Tue, 20 Jul 2021 15:25:49 -0700 Subject: [PATCH] Add implicit conversion operators to AspectRatio so it can be used in mathmatical expressions and double can be bound from x:Bind directly! --- .../ConstrainedPresenter/AspectRatio.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls.Primitives/ConstrainedPresenter/AspectRatio.cs b/Microsoft.Toolkit.Uwp.UI.Controls.Primitives/ConstrainedPresenter/AspectRatio.cs index 0e30671a631..f2d2cf559a0 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls.Primitives/ConstrainedPresenter/AspectRatio.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls.Primitives/ConstrainedPresenter/AspectRatio.cs @@ -49,6 +49,20 @@ public AspectRatio(double ratio) Height = 1; } + /// + /// Implicit conversion operator to convert an to a value. + /// This lets you use them easily in mathmatical expressions. + /// + /// instance. + public static implicit operator double(AspectRatio aspect) => aspect.Value; + + /// + /// Implicit conversion operator to convert a to an value. + /// This allows for x:Bind to bind to a double value. + /// + /// value representing the . + public static implicit operator AspectRatio(double ratio) => new AspectRatio(ratio); + /// /// Converter to take a string aspect ration like "16:9" and convert it to an struct. /// Used automatically by XAML.