Skip to content

Commit

Permalink
Merge pull request #2 from MahApps/master
Browse files Browse the repository at this point in the history
Merge MahApps master
  • Loading branch information
Stefan Schweiger committed Oct 7, 2013
2 parents db71500 + b2dd280 commit 26dafd6
Show file tree
Hide file tree
Showing 51 changed files with 3,576 additions and 1,425 deletions.
10 changes: 5 additions & 5 deletions MahApps.Metro/Controls/ProgressIndicator.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,27 +75,27 @@
</UserControl.Triggers>
<Border x:Name="IndeterminateRoot" Visibility="Visible" VerticalAlignment="Stretch">
<Grid VerticalAlignment="Stretch" Margin="0" HorizontalAlignment="Left">
<Rectangle Fill="{Binding ProgressColour}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="4" x:Name="R1" HorizontalAlignment="Left" >
<Rectangle Fill="{Binding Path=ProgressColour,ElementName=progressIndicator}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="4" x:Name="R1" HorizontalAlignment="Left" >
<Rectangle.RenderTransform>
<TranslateTransform x:Name="R1TT" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Fill="{Binding ProgressColour}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="4" x:Name="R2" HorizontalAlignment="Left" >
<Rectangle Fill="{Binding Path=ProgressColour,ElementName=progressIndicator}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="4" x:Name="R2" HorizontalAlignment="Left" >
<Rectangle.RenderTransform>
<TranslateTransform x:Name="R2TT" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Fill="{Binding ProgressColour}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="4" x:Name="R3" HorizontalAlignment="Left" >
<Rectangle Fill="{Binding Path=ProgressColour,ElementName=progressIndicator}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="4" x:Name="R3" HorizontalAlignment="Left" >
<Rectangle.RenderTransform>
<TranslateTransform x:Name="R3TT" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Fill="{Binding ProgressColour}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="4" x:Name="R4" HorizontalAlignment="Left" >
<Rectangle Fill="{Binding Path=ProgressColour,ElementName=progressIndicator}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="4" x:Name="R4" HorizontalAlignment="Left" >
<Rectangle.RenderTransform>
<TranslateTransform x:Name="R4TT" />
</Rectangle.RenderTransform>
</Rectangle>
<Rectangle Fill="{Binding ProgressColour}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="4" x:Name="R5" HorizontalAlignment="Left" >
<Rectangle Fill="{Binding Path=ProgressColour,ElementName=progressIndicator}" VerticalAlignment="Stretch" IsHitTestVisible="False" Width="4" x:Name="R5" HorizontalAlignment="Left" >
<Rectangle.RenderTransform>
<TranslateTransform x:Name="R5TT" />
</Rectangle.RenderTransform>
Expand Down
2 changes: 1 addition & 1 deletion MahApps.Metro/Controls/ProgressIndicator.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public partial class ProgressIndicator
public ProgressIndicator()
{
InitializeComponent();
this.DataContext = this;

IsVisibleChanged += (s, e) => ((ProgressIndicator)s).StartStopAnimation();
DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(VisibilityProperty, GetType());
dpd.AddValueChanged(this, (s, e) => ((ProgressIndicator)s).StartStopAnimation());
Expand Down
19 changes: 13 additions & 6 deletions MahApps.Metro/Controls/ToggleSwitch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,14 @@ public class ToggleSwitch : ContentControl
private ToggleButton _toggleButton;
private bool _wasContentSet;

public static readonly DependencyProperty OnProperty = DependencyProperty.Register("OnLabel", typeof(string), typeof(ToggleSwitch), new PropertyMetadata("On"));
public static readonly DependencyProperty OffProperty = DependencyProperty.Register("OffLabel", typeof(string), typeof(ToggleSwitch), new PropertyMetadata("Off"));
public static readonly DependencyProperty OnLabelProperty = DependencyProperty.Register("OnLabel", typeof(string), typeof(ToggleSwitch), new PropertyMetadata("On"));
public static readonly DependencyProperty OffLabelProperty = DependencyProperty.Register("OffLabel", typeof(string), typeof(ToggleSwitch), new PropertyMetadata("Off"));
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register("Header", typeof(object), typeof(ToggleSwitch), new PropertyMetadata(null));
public static readonly DependencyProperty HeaderTemplateProperty = DependencyProperty.Register("HeaderTemplate", typeof(DataTemplate), typeof(ToggleSwitch), new PropertyMetadata(null));
public static readonly DependencyProperty SwitchForegroundProperty = DependencyProperty.Register("SwitchForeground", typeof(Brush), typeof(ToggleSwitch), null);
public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool?), typeof(ToggleSwitch), new FrameworkPropertyMetadata(false, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnIsCheckedChanged));
// LeftToRight means content left and button right and RightToLeft vise versa
public static readonly DependencyProperty ContentDirectionProperty = DependencyProperty.Register("ContentDirection", typeof(FlowDirection), typeof(ToggleSwitch), new PropertyMetadata(FlowDirection.LeftToRight));

public event EventHandler<RoutedEventArgs> Checked;
public event EventHandler<RoutedEventArgs> Unchecked;
Expand All @@ -42,14 +44,14 @@ public class ToggleSwitch : ContentControl

public string OnLabel
{
get { return (string)GetValue(OnProperty); }
set { SetValue(OnProperty, value); }
get { return (string)GetValue(OnLabelProperty); }
set { SetValue(OnLabelProperty, value); }
}

public string OffLabel
{
get { return (string)GetValue(OffProperty); }
set { SetValue(OffProperty, value); }
get { return (string)GetValue(OffLabelProperty); }
set { SetValue(OffLabelProperty, value); }
}

public object Header
Expand All @@ -73,6 +75,11 @@ public Brush SwitchForeground
}
}

public FlowDirection ContentDirection {
get { return (FlowDirection)GetValue(ContentDirectionProperty); }
set { SetValue(ContentDirectionProperty, value); }
}

[TypeConverter(typeof(NullableBoolConverter))]
public bool? IsChecked
{
Expand Down
59 changes: 59 additions & 0 deletions MahApps.Metro/Converters/BackgroundToForegroundConverter.cs
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;
}
}
}
43 changes: 43 additions & 0 deletions MahApps.Metro/Converters/FontSizeOffsetConverter.cs
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;
}
}
}
25 changes: 0 additions & 25 deletions MahApps.Metro/Converters/LeftMarginMultiplierConverter.cs

This file was deleted.

51 changes: 51 additions & 0 deletions MahApps.Metro/Converters/TreeViewMarginConverter.cs
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;
}
}
}
Loading

0 comments on commit 26dafd6

Please sign in to comment.