Skip to content

Commit 39a95f2

Browse files
Add implicit conversion operators to AspectRatio so it can be used in mathmatical expressions and double can be bound from x:Bind directly!
1 parent 2fe411d commit 39a95f2

File tree

1 file changed

+14
-0
lines changed
  • Microsoft.Toolkit.Uwp.UI.Controls.Primitives/ConstrainedPresenter

1 file changed

+14
-0
lines changed

Microsoft.Toolkit.Uwp.UI.Controls.Primitives/ConstrainedPresenter/AspectRatio.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,20 @@ public AspectRatio(double ratio)
4949
Height = 1;
5050
}
5151

52+
/// <summary>
53+
/// Implicit conversion operator to convert an <see cref="AspectRatio"/> to a <see cref="double"/> value.
54+
/// This lets you use them easily in mathmatical expressions.
55+
/// </summary>
56+
/// <param name="aspect"><see cref="AspectRatio"/> instance.</param>
57+
public static implicit operator double(AspectRatio aspect) => aspect.Value;
58+
59+
/// <summary>
60+
/// Implicit conversion operator to convert a <see cref="double"/> to an <see cref="AspectRatio"/> value.
61+
/// This allows for x:Bind to bind to a double value.
62+
/// </summary>
63+
/// <param name="ratio"><see cref="double"/> value representing the <see cref="AspectRatio"/>.</param>
64+
public static implicit operator AspectRatio(double ratio) => new AspectRatio(ratio);
65+
5266
/// <summary>
5367
/// Converter to take a string aspect ration like "16:9" and convert it to an <see cref="AspectRatio"/> struct.
5468
/// Used automatically by XAML.

0 commit comments

Comments
 (0)