-
-
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.
Merge pull request #2 from MahApps/master
Merge MahApps master
- Loading branch information
Showing
51 changed files
with
3,576 additions
and
1,425 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
59 changes: 59 additions & 0 deletions
59
MahApps.Metro/Converters/BackgroundToForegroundConverter.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,59 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
using System.Windows.Media; | ||
|
||
namespace MahApps.Metro.Converters | ||
{ | ||
public class BackgroundToForegroundConverter : IValueConverter | ||
{ | ||
private static BackgroundToForegroundConverter _instance; | ||
|
||
// Explicit static constructor to tell C# compiler | ||
// not to mark type as beforefieldinit | ||
static BackgroundToForegroundConverter() | ||
{ | ||
} | ||
|
||
private BackgroundToForegroundConverter() | ||
{ | ||
} | ||
|
||
public static BackgroundToForegroundConverter Instance | ||
{ | ||
get { return _instance ?? (_instance = new BackgroundToForegroundConverter()); } | ||
} | ||
|
||
/// <summary> | ||
/// Determining Ideal Text Color Based on Specified Background Color | ||
/// http://www.codeproject.com/KB/GDI-plus/IdealTextColor.aspx | ||
/// </summary> | ||
/// <param name = "bg">The bg.</param> | ||
/// <returns></returns> | ||
private Color IdealTextColor(Color bg) | ||
{ | ||
const int nThreshold = 105; | ||
var bgDelta = System.Convert.ToInt32((bg.R * 0.299) + (bg.G * 0.587) + (bg.B * 0.114)); | ||
var foreColor = (255 - bgDelta < nThreshold) ? Colors.Black : Colors.White; | ||
return foreColor; | ||
} | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is SolidColorBrush) | ||
{ | ||
var idealForegroundColor = this.IdealTextColor(((SolidColorBrush)value).Color); | ||
var foreGroundBrush = new SolidColorBrush(idealForegroundColor); | ||
foreGroundBrush.Freeze(); | ||
return foreGroundBrush; | ||
} | ||
return Brushes.White; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
using System; | ||
using System.Globalization; | ||
using System.Windows; | ||
using System.Windows.Data; | ||
|
||
namespace MahApps.Metro.Converters | ||
{ | ||
// this converter is only used by DatePicker to convert the font size to width and height of the icon button | ||
public class FontSizeOffsetConverter : IValueConverter | ||
{ | ||
private static FontSizeOffsetConverter _instance; | ||
|
||
// Explicit static constructor to tell C# compiler | ||
// not to mark type as beforefieldinit | ||
static FontSizeOffsetConverter() | ||
{ | ||
} | ||
|
||
private FontSizeOffsetConverter() | ||
{ | ||
} | ||
|
||
public static FontSizeOffsetConverter Instance | ||
{ | ||
get { return _instance ?? (_instance = new FontSizeOffsetConverter()); } | ||
} | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
if (value is double && parameter is double) { | ||
var offset = (double)parameter; | ||
var orgValue = (double)value; | ||
return Math.Round(orgValue + offset); | ||
} | ||
return value; | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
return DependencyProperty.UnsetValue; | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
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; | ||
using System.Windows.Controls; | ||
using System.Windows.Data; | ||
using System.Windows.Media; | ||
|
||
namespace MahApps.Metro.Converters | ||
{ | ||
public class TreeViewMarginConverter : IValueConverter | ||
{ | ||
public double Length { get; set; } | ||
|
||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
var item = value as TreeViewItem; | ||
if (item == null) | ||
return new Thickness(0); | ||
|
||
return new Thickness(Length * item.GetDepth(), 0, 0, 0); | ||
} | ||
|
||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) | ||
{ | ||
throw new NotImplementedException(); | ||
} | ||
} | ||
|
||
public static class TreeViewItemExtensions | ||
{ | ||
public static int GetDepth(this TreeViewItem item) | ||
{ | ||
TreeViewItem parent; | ||
while ((parent = GetParent(item)) != null) | ||
{ | ||
return GetDepth(parent) + 1; | ||
} | ||
return 0; | ||
} | ||
|
||
private static TreeViewItem GetParent(TreeViewItem item) | ||
{ | ||
var parent = VisualTreeHelper.GetParent(item); | ||
while (!(parent is TreeViewItem || parent is TreeView)) | ||
{ | ||
parent = VisualTreeHelper.GetParent(parent); | ||
} | ||
return parent as TreeViewItem; | ||
} | ||
} | ||
} |
Oops, something went wrong.