Skip to content

Commit

Permalink
Add implicit conversion operators to AspectRatio so it can be used in…
Browse files Browse the repository at this point in the history
… mathmatical expressions and double can be bound from x:Bind directly!
  • Loading branch information
michael-hawker committed Jul 20, 2021
1 parent 16f70bf commit 4fe6c67
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,20 @@ public AspectRatio(double ratio)
Height = 1;
}

/// <summary>
/// Implicit conversion operator to convert an <see cref="AspectRatio"/> to a <see cref="double"/> value.
/// This lets you use them easily in mathmatical expressions.
/// </summary>
/// <param name="aspect"><see cref="AspectRatio"/> instance.</param>
public static implicit operator double(AspectRatio aspect) => aspect.Value;

/// <summary>
/// Implicit conversion operator to convert a <see cref="double"/> to an <see cref="AspectRatio"/> value.
/// This allows for x:Bind to bind to a double value.
/// </summary>
/// <param name="ratio"><see cref="double"/> value representing the <see cref="AspectRatio"/>.</param>
public static implicit operator AspectRatio(double ratio) => new AspectRatio(ratio);

/// <summary>
/// Converter to take a string aspect ration like "16:9" and convert it to an <see cref="AspectRatio"/> struct.
/// Used automatically by XAML.
Expand Down

0 comments on commit 4fe6c67

Please sign in to comment.