Mono XAML/Utility/Utility.cs
/// <summary>
/// Returns a color based on a XAML brush
/// </summary>
/// <param name="position">Specifies position in the space (0, 0) to (1, 0) - out of bounds values will be clamped</param>
/// <param name="brush">Brush specified from XAML Designer</param>
Returns a color based on a XAML brush
Returns a color based on a XAML brush
public static Microsoft.Xna.Framework.Color GetColor(Vector2 position, Brush brush)
        {
            position = Vector2.Clamp(position, Vector2.Zero, Vector2.One);
            if(brush is GradientBrush gradient)
            {
                return GetColor(position, brush);
            }
            else if(brush is SolidColorBrush solidColor)
            {
                return solidColor.Color.Convert();
            }
            else
            {
                throw new NotImplementedException("Does not recognize " + brush.GetType());
            }
        }
public static Microsoft . Xna . Framework . Color GetColor ( Vector2 position , Brush brush ) { position = Vector2 . Clamp ( position , Vector2 . Zero , Vector2 . One ) ; if ( brush is GradientBrush gradient ) { return GetColor ( position , brush ) ; } else if ( brush is SolidColorBrush solidColor ) { return solidColor . Color . Convert ( ) ; } else { throw new NotImplementedException ( " " + brush . GetType ( ) ) ; } }
Returns a color based on a XAML brush
Returns a color based on a XAML brush
position
Vector2
Specifies position in the space (0, 0) to (1, 0) - out of bounds values will be clamped
Specifies position in the space ( 0 0 ) to ( 1 0 ) - out of bounds values will be clamped
brush
Brush
Brush specified from XAML Designer
Brush specified from XAML Designer