-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from ChrisPulman/AddConverters
Add Converters
- Loading branch information
Showing
23 changed files
with
113 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Chris Pulman. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Globalization; | ||
using System.Windows.Data; | ||
using System.Windows.Media; | ||
|
||
namespace CP.Xaml.Converters; | ||
|
||
/// <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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright (c) Chris Pulman. All rights reserved. | ||
// Licensed under the MIT license. See LICENSE file in the project root for full license information. | ||
|
||
using System.Globalization; | ||
using System.Windows.Data; | ||
using System.Windows.Media; | ||
|
||
namespace CP.Xaml.Converters; | ||
|
||
/// <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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters