-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
237 additions
and
47 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
51 changes: 51 additions & 0 deletions
51
src/MahApps.Metro/Converters/ColorToSolidColorBrushConverter.cs
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,51 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows.Data; | ||
using System.Windows.Media; | ||
using JetBrains.Annotations; | ||
|
||
namespace MahApps.Metro.Converters | ||
{ | ||
/// <summary> | ||
/// Converts a given <see cref="Color"/> into a <see cref="SolidColorBrush"/>. | ||
/// </summary> | ||
[ValueConversion(typeof(Color), typeof(SolidColorBrush))] | ||
public class ColorToSolidColorBrushConverter : IValueConverter | ||
{ | ||
private static ColorToSolidColorBrushConverter defaultInstance; | ||
|
||
/// <summary> | ||
/// Gets a static instance of the converter if needed. | ||
/// </summary> | ||
public static ColorToSolidColorBrushConverter DefaultInstance => defaultInstance ??= new ColorToSolidColorBrushConverter(); | ||
|
||
/// <summary> | ||
/// Gets or Sets the brush which will be used if the conversion fails. | ||
/// </summary> | ||
[CanBeNull] | ||
public SolidColorBrush FallbackBrush { get; set; } | ||
|
||
/// <summary> | ||
/// Gets or Sets the color which will be used if the conversion fails. | ||
/// </summary> | ||
[CanBeNull] | ||
public Color? FallbackColor { get; set; } | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is Color color) | ||
{ | ||
var brush = new SolidColorBrush(color); | ||
brush.Freeze(); | ||
return brush; | ||
} | ||
|
||
return this.FallbackBrush; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return value is SolidColorBrush brush ? brush.Color : this.FallbackColor; | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
src/MahApps.Metro/Converters/CornerRadiusFilterConverter.cs
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,63 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Globalization; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
|
||
namespace MahApps.Metro.Converters | ||
{ | ||
/// <summary> | ||
/// Filters a CornerRadius by the given Filter property. Result can be a new CornerRadius or a value of it's 4 corners. | ||
/// </summary> | ||
public class CornerRadiusFilterConverter : IValueConverter | ||
{ | ||
public RadiusType Filter { get; set; } = RadiusType.None; | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is CornerRadius cornerRadius) | ||
{ | ||
var filter = this.Filter; | ||
|
||
// yes, we can override it with the parameter value | ||
if (parameter is RadiusType radiusType) | ||
{ | ||
filter = radiusType; | ||
} | ||
|
||
switch (filter) | ||
{ | ||
default: | ||
return cornerRadius; | ||
case RadiusType.Left: | ||
return new CornerRadius(cornerRadius.TopLeft, 0, 0, cornerRadius.BottomLeft); | ||
case RadiusType.Top: | ||
return new CornerRadius(cornerRadius.TopLeft, cornerRadius.TopRight, 0, 0); | ||
case RadiusType.Right: | ||
return new CornerRadius(0, cornerRadius.TopRight, cornerRadius.BottomRight, 0); | ||
case RadiusType.Bottom: | ||
return new CornerRadius(0, 0, cornerRadius.BottomRight, cornerRadius.BottomLeft); | ||
case RadiusType.TopLeft: | ||
return cornerRadius.TopLeft; | ||
case RadiusType.TopRight: | ||
return cornerRadius.TopRight; | ||
case RadiusType.BottomRight: | ||
return cornerRadius.BottomRight; | ||
case RadiusType.BottomLeft: | ||
return cornerRadius.BottomLeft; | ||
} | ||
} | ||
|
||
return Binding.DoNothing; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
// for now no back converting | ||
return DependencyProperty.UnsetValue; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.