Skip to content

Commit

Permalink
Add Comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisPulman committed Jan 20, 2024
1 parent 26704fc commit 46b2718
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 2 deletions.
26 changes: 25 additions & 1 deletion src/XamlConverters/BrushToColorConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,38 @@

namespace CP.Xaml.Converters;

internal class BrushToColorConverter : IValueConverter
/// <summary>
/// BrushToColorConverter.
/// </summary>
/// <seealso cref="System.Windows.Data.IValueConverter" />
public class BrushToColorConverter : IValueConverter
{
/// <summary>
/// Converts a value.
/// </summary>
/// <param name="value">The value produced by the binding source.</param>
/// <param name="targetType">The type of the binding target property.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>
/// A converted value. If the method returns null, the valid null value is used.
/// </returns>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => value switch
{
SolidColorBrush brush => brush.Color,
Color color => color,
_ => Colors.Red
};

/// <summary>
/// Converts a value.
/// </summary>
/// <param name="value">The value that is produced by the binding target.</param>
/// <param name="targetType">The type to convert to.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>
/// A converted value. If the method returns null, the valid null value is used.
/// </returns>
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => Binding.DoNothing;
}
26 changes: 25 additions & 1 deletion src/XamlConverters/FallbackBrushConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,38 @@

namespace CP.Xaml.Converters;

internal class FallbackBrushConverter : IValueConverter
/// <summary>
/// FallbackBrushConverter.
/// </summary>
/// <seealso cref="System.Windows.Data.IValueConverter" />
public class FallbackBrushConverter : IValueConverter
{
/// <summary>
/// Converts a value.
/// </summary>
/// <param name="value">The value produced by the binding source.</param>
/// <param name="targetType">The type of the binding target property.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>
/// A converted value. If the method returns null, the valid null value is used.
/// </returns>
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) => value switch
{
SolidColorBrush brush => brush,
Color color => new SolidColorBrush(color),
_ => new SolidColorBrush(Colors.Red)
};

/// <summary>
/// Converts a value.
/// </summary>
/// <param name="value">The value that is produced by the binding target.</param>
/// <param name="targetType">The type to convert to.</param>
/// <param name="parameter">The converter parameter to use.</param>
/// <param name="culture">The culture to use in the converter.</param>
/// <returns>
/// A converted value. If the method returns null, the valid null value is used.
/// </returns>
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) => Binding.DoNothing;
}

0 comments on commit 46b2718

Please sign in to comment.