Skip to content

Commit

Permalink
Merge branch 'develop' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
punker76 committed Dec 1, 2020
2 parents d43eabe + 821d15d commit 1f8ca06
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 32 deletions.
6 changes: 6 additions & 0 deletions src/MahApps.Metro.Samples/MahApps.Metro.Demo/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@
<Setter Property="mah:HeaderedControlHelper.HeaderVerticalContentAlignment" Value="Center" />
</Style>

<Style x:Key="MahApps.Styles.ColorPalette.ColorPickerDropDown"
BasedOn="{StaticResource MahApps.Styles.ColorPalette}"
TargetType="{x:Type mah:ColorPalette}">
<Setter Property="mah:ControlsHelper.ContentCharacterCasing" Value="Normal" />
</Style>

</ResourceDictionary>
</Application.Resources>
</Application>
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
</GroupBox>

<GroupBox Margin="5 5 5 0" Header="Color Canvas">
<mah:ColorCanvas x:Name="ColorCanvasExample" SelectedColor="Blue" />
<mah:ColorCanvas x:Name="ColorCanvasExample" DefaultColor="{DynamicResource MahApps.Colors.AccentBase}" />
</GroupBox>

<GroupBox Margin="5" Header="Color Picker">
Expand Down
8 changes: 0 additions & 8 deletions src/MahApps.Metro/Controls/ColorPicker/ColorPicker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -758,9 +758,6 @@ internal override void OnSelectedColorChanged(Color? oldValue, Color? newValue)
{
base.OnSelectedColorChanged(newValue, oldValue);

// Set color is Updating again
this.ColorIsUpdating = true;

this.PART_ColorPaletteAvailable?.SetCurrentValue(Selector.SelectedValueProperty, newValue);
this.PART_ColorPaletteStandard?.SetCurrentValue(Selector.SelectedValueProperty, newValue);
this.PART_ColorPaletteCustom01?.SetCurrentValue(Selector.SelectedValueProperty, newValue);
Expand All @@ -771,8 +768,6 @@ internal override void OnSelectedColorChanged(Color? oldValue, Color? newValue)
{
BuildInColorPalettes.AddColorToRecentColors(newValue, this.RecentColorPaletteItemsSource, BuildInColorPalettes.GetMaximumRecentColorsCount(this));
}

this.ColorIsUpdating = false;
}

private void ColorPalette_SelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down Expand Up @@ -841,10 +836,7 @@ private static void OnIsDropDownOpenChanged(DependencyObject d, DependencyProper

if (colorPicker.AddToRecentColorsTrigger == AddToRecentColorsTrigger.ColorPickerClosed && colorPicker.SelectedColor.HasValue)
{
// We Update something so we need to flag this
colorPicker.ColorIsUpdating = true;
BuildInColorPalettes.AddColorToRecentColors(colorPicker.SelectedColor, colorPicker.RecentColorPaletteItemsSource, BuildInColorPalettes.GetMaximumRecentColorsCount(colorPicker));
colorPicker.ColorIsUpdating = false;
}
}
}
Expand Down
47 changes: 26 additions & 21 deletions src/MahApps.Metro/Controls/ColorPicker/ColorPickerBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,26 @@ public class ColorPickerBase : Control
= DependencyProperty.Register(nameof(SelectedColor),
typeof(Color?),
typeof(ColorPickerBase),
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSelectedColorPropertyChanged));
new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnSelectedColorPropertyChanged, CoerceSelectedColorProperty));

private static void OnSelectedColorPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
if (dependencyObject is ColorPickerBase colorPicker && e.OldValue != e.NewValue && !colorPicker.ColorIsUpdating)
{
colorPicker.ColorIsUpdating = true;
colorPicker.OnSelectedColorChanged(e.OldValue as Color?, e.NewValue as Color? ?? colorPicker.DefaultColor);
colorPicker.ColorIsUpdating = false;
}
}

private static object CoerceSelectedColorProperty(DependencyObject dependencyObject, object basevalue)
{
if (dependencyObject is ColorPickerBase colorPicker)
{
colorPicker.OnSelectedColorChanged(e.OldValue as Color?, e.NewValue as Color?);
basevalue ??= colorPicker.DefaultColor;
}

return basevalue;
}

/// <summary>
Expand All @@ -46,7 +58,15 @@ private static void OnSelectedColorPropertyChanged(DependencyObject dependencyOb
= DependencyProperty.Register(nameof(DefaultColor),
typeof(Color?),
typeof(ColorPickerBase),
new FrameworkPropertyMetadata(null, OnSelectedColorPropertyChanged));
new FrameworkPropertyMetadata(null, OnDefaultColorPropertyChanged));

private static void OnDefaultColorPropertyChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e)
{
if (dependencyObject is ColorPickerBase colorPicker && e.OldValue != e.NewValue)
{
colorPicker.SetCurrentValue(SelectedColorProperty, e.NewValue ?? colorPicker.SelectedColor);
}
}

/// <summary>
/// Gets or sets a default selected <see cref="Color"/>
Expand Down Expand Up @@ -411,25 +431,12 @@ public object LabelColorName

internal virtual void OnSelectedColorChanged(Color? oldValue, Color? newValue)
{
// don't do a second update
if (this.ColorIsUpdating)
{
return;
}

this.ColorIsUpdating = true;

if (this.SelectedColor == null && this.DefaultColor != null)
{
this.SetCurrentValue(SelectedColorProperty, this.DefaultColor);
}

this.SetCurrentValue(ColorNameProperty, ColorHelper.GetColorName(this.SelectedColor, this.ColorNamesDictionary));
this.SetCurrentValue(ColorNameProperty, ColorHelper.GetColorName(newValue, this.ColorNamesDictionary));

// We just update the following lines if we have a Color.
if (this.SelectedColor != null)
if (newValue != null)
{
var color = (Color)this.SelectedColor;
var color = (Color)newValue;

if (this.UpdateHsvValues)
{
Expand All @@ -447,8 +454,6 @@ internal virtual void OnSelectedColorChanged(Color? oldValue, Color? newValue)
this.SetCurrentValue(BProperty, color.B);
}

this.ColorIsUpdating = false;

this.RaiseEvent(new RoutedPropertyChangedEventArgs<Color?>(oldValue, newValue, SelectedColorChangedEvent));
}

Expand Down
1 change: 1 addition & 0 deletions src/MahApps.Metro/Controls/Helper/ControlsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public static void SetDisabledVisualElementVisibility(UIElement element, Visibil
[AttachedPropertyBrowsableForType(typeof(DropDownButton))]
[AttachedPropertyBrowsableForType(typeof(SplitButton))]
[AttachedPropertyBrowsableForType(typeof(WindowCommands))]
[AttachedPropertyBrowsableForType(typeof(ColorPalette))]
public static CharacterCasing GetContentCharacterCasing(UIElement element)
{
return (CharacterCasing)element.GetValue(ContentCharacterCasingProperty);
Expand Down
9 changes: 7 additions & 2 deletions src/MahApps.Metro/Themes/ColorPicker/ColorPalette.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@
</Border>
</DataTemplate>

<Style x:Key="MahApps.Styles.ColorPalette" TargetType="mah:ColorPalette">
<Style x:Key="MahApps.Styles.ColorPalette" TargetType="{x:Type mah:ColorPalette}">
<Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.Accent}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="Focusable" Value="False" />
Expand All @@ -138,9 +138,10 @@
<Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Disabled" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="mah:ColorPalette">
<ControlTemplate TargetType="{x:Type mah:ColorPalette}">
<GroupBox Margin="{TemplateBinding Margin}"
Padding="{TemplateBinding Padding}"
mah:ControlsHelper.ContentCharacterCasing="{TemplateBinding mah:ControlsHelper.ContentCharacterCasing}"
mah:HeaderedControlHelper.HeaderBackground="{TemplateBinding mah:HeaderedControlHelper.HeaderBackground}"
mah:HeaderedControlHelper.HeaderFontFamily="{TemplateBinding mah:HeaderedControlHelper.HeaderFontFamily}"
mah:HeaderedControlHelper.HeaderFontSize="{TemplateBinding mah:HeaderedControlHelper.HeaderFontSize}"
Expand Down Expand Up @@ -174,4 +175,8 @@
<Setter Property="mah:HeaderedControlHelper.HeaderForeground" Value="{DynamicResource MahApps.Brushes.IdealForeground}" />
</Style>

<Style x:Key="MahApps.Styles.ColorPalette.ColorPickerDropDown"
BasedOn="{StaticResource MahApps.Styles.ColorPalette}"
TargetType="{x:Type mah:ColorPalette}" />

</ResourceDictionary>

0 comments on commit 1f8ca06

Please sign in to comment.