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 Feb 28, 2021
2 parents 272e559 + 11afa2b commit 29a0ac4
Show file tree
Hide file tree
Showing 21 changed files with 237 additions and 47 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,8 @@ src/MahApps.Metro/Styles/Themes/*.xaml
!src/MahApps.Metro/Styles/Themes/Theme.Template.xaml

# cake
tools/
tools/*
!tools/packages.config

# XamlStyler
!XamlStyler/
18 changes: 9 additions & 9 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
// TOOLS / ADDINS
///////////////////////////////////////////////////////////////////////////////

#module nuget:?package=Cake.DotNetTool.Module
#tool "dotnet:?package=NuGetKeyVaultSignTool&version=1.2.28"
#tool "dotnet:?package=AzureSignTool&version=2.0.17"

#tool GitVersion.CommandLine&version=5.5.1
#tool gitreleasemanager
#tool xunit.runner.console
#tool vswhere
#addin Cake.Figlet
#module nuget:?package=Cake.DotNetTool.Module&version=0.5.0
#tool dotnet:?package=NuGetKeyVaultSignTool&version=1.2.28
#tool dotnet:?package=AzureSignTool&version=2.0.17
#tool dotnet:?package=GitReleaseManager.Tool&version=0.11.0
#tool dotnet:?package=GitVersion.Tool&version=5.6.6

#tool xunit.runner.console&version=2.4.1
#tool vswhere&version=2.8.4
#addin nuget:?package=Cake.Figlet&version=1.4.0

///////////////////////////////////////////////////////////////////////////////
// ARGUMENTS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@
</StackPanel.Resources>

<Label Content="CheckBox Win10" Style="{DynamicResource DescriptionHeaderStyle}" />
<CheckBox IsChecked="False" IsEnabled="True" />
<CheckBox IsChecked="False" IsEnabled="True" mah:CheckBoxHelper.CheckCornerRadius="2" />
<CheckBox IsChecked="False" IsEnabled="False" />
<CheckBox IsChecked="True" IsEnabled="False" />
<CheckBox IsChecked="True" IsEnabled="True" />
Expand Down
18 changes: 16 additions & 2 deletions src/MahApps.Metro/Behaviors/WindowsSettingBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,14 @@ private void AssociatedObject_SourceInitialized(object sender, EventArgs e)
window.Closed += this.AssociatedObject_Closed;

// This operation must be thread safe
Application.Current?.BeginInvoke(() => Application.Current.SessionEnding += this.CurrentApplicationSessionEnding);
window.BeginInvoke(() =>
{
var application = Application.Current;
if (application != null)
{
application.SessionEnding += this.CurrentApplicationSessionEnding;
}
});
}

private void AssociatedObject_Closing(object sender, System.ComponentModel.CancelEventArgs e)
Expand Down Expand Up @@ -93,7 +100,14 @@ private void CleanUp(string fromWhere)
window.SourceInitialized -= this.AssociatedObject_SourceInitialized;

// This operation must be thread safe
Application.Current?.BeginInvoke(() => Application.Current.SessionEnding -= this.CurrentApplicationSessionEnding);
window.BeginInvoke(() =>
{
var application = Application.Current;
if (application != null)
{
application.SessionEnding -= this.CurrentApplicationSessionEnding;
}
});
}

#pragma warning disable 618
Expand Down
26 changes: 26 additions & 0 deletions src/MahApps.Metro/Controls/FlipView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace MahApps.Metro.Controls
[TemplatePart(Name = PART_DownButton, Type = typeof(Button))]
[TemplatePart(Name = PART_BannerGrid, Type = typeof(Grid))]
[TemplatePart(Name = PART_BannerLabel, Type = typeof(Label))]
[TemplatePart(Name = PART_Index, Type = typeof(ListBox))]
[StyleTypedProperty(Property = nameof(NavigationButtonStyle), StyleTargetType = typeof(Button))]
[StyleTypedProperty(Property = nameof(IndexItemContainerStyle), StyleTargetType = typeof(ListBoxItem))]
public class FlipView : Selector
Expand Down Expand Up @@ -696,13 +697,15 @@ public string ButtonDownContentStringFormat
private const string PART_ForwardButton = "PART_ForwardButton";
private const string PART_Presenter = "PART_Presenter";
private const string PART_UpButton = "PART_UpButton";
private const string PART_Index = "PART_Index";
/// <summary>
/// To counteract the double Loaded event issue.
/// </summary>
private bool loaded;
private bool allowSelectedIndexChangedCallback = true;
private Grid bannerGrid;
private Label bannerLabel;
private ListBox indexListBox;
private Button backButton;
private Button forwardButton;
private Button downButton;
Expand Down Expand Up @@ -859,6 +862,11 @@ public override void OnApplyTemplate()

this.presenter = this.GetTemplateChild(PART_Presenter) as TransitioningContentControl;

if (this.indexListBox != null)
{
this.indexListBox.SelectionChanged -= OnIndexListBoxSelectionChanged;
}

if (this.forwardButton != null)
{
this.forwardButton.Click -= this.NextButtonClick;
Expand All @@ -879,6 +887,8 @@ public override void OnApplyTemplate()
this.downButton.Click -= this.NextButtonClick;
}

this.indexListBox = this.GetTemplateChild(PART_Index) as ListBox;

this.forwardButton = this.GetTemplateChild(PART_ForwardButton) as Button;
this.backButton = this.GetTemplateChild(PART_BackButton) as Button;
this.upButton = this.GetTemplateChild(PART_UpButton) as Button;
Expand Down Expand Up @@ -911,6 +921,22 @@ public override void OnApplyTemplate()
{
this.bannerLabel.Opacity = this.IsBannerEnabled ? 1d : 0d;
}

this.ExecuteWhenLoaded(() =>
{
if (this.indexListBox != null)
{
this.indexListBox.SelectionChanged += OnIndexListBoxSelectionChanged;
}
});
}

private void OnIndexListBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (ReferenceEquals(e.OriginalSource, this.indexListBox))
{
e.Handled = true;
}
}

protected override DependencyObject GetContainerForItemOverride()
Expand Down
30 changes: 30 additions & 0 deletions src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,36 @@ public static void SetCheckSize(DependencyObject obj, double value)
obj.SetValue(CheckSizeProperty, value);
}

public static readonly DependencyProperty CheckCornerRadiusProperty
= DependencyProperty.RegisterAttached(
"CheckCornerRadius",
typeof(CornerRadius),
typeof(CheckBoxHelper),
new FrameworkPropertyMetadata(
new CornerRadius(),
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));

/// <summary>
/// Gets the CornerRadius of the CheckBox itself.
/// The CheckCornerRadius property allows users to control the roundness of the CheckBox corners independently by setting a radius value for each corner.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static CornerRadius GetCheckCornerRadius(UIElement element)
{
return (CornerRadius)element.GetValue(CheckCornerRadiusProperty);
}

/// <summary>
/// Sets the CornerRadius of the CheckBox itself.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
public static void SetCheckCornerRadius(UIElement element, CornerRadius value)
{
element.SetValue(CheckCornerRadiusProperty, value);
}

public static readonly DependencyProperty CheckStrokeThicknessProperty
= DependencyProperty.RegisterAttached(
"CheckStrokeThickness",
Expand Down
6 changes: 3 additions & 3 deletions src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -931,11 +931,11 @@ public static void ButtonClicked(object sender, RoutedEventArgs e)
{
if (comboBox.IsEditable)
{
comboBox.Text = string.Empty;
comboBox.SetCurrentValue(ComboBox.TextProperty, string.Empty);
comboBox.GetBindingExpression(ComboBox.TextProperty)?.UpdateSource();
}

comboBox.SelectedItem = null;
comboBox.SetCurrentValue(ComboBox.SelectedItemProperty, null);
comboBox.GetBindingExpression(ComboBox.SelectedItemProperty)?.UpdateSource();
}
else if (parent is ColorPickerBase colorPicker)
Expand Down Expand Up @@ -1020,4 +1020,4 @@ private static void ComboBoxLoaded(object sender, RoutedEventArgs e)
}
}
}
}
}
51 changes: 51 additions & 0 deletions src/MahApps.Metro/Converters/ColorToSolidColorBrushConverter.cs
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 src/MahApps.Metro/Converters/CornerRadiusFilterConverter.cs
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;
}
}
}
7 changes: 6 additions & 1 deletion src/MahApps.Metro/Styles/Controls.CheckBox.xaml
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mah="clr-namespace:MahApps.Metro.Controls"
xmlns:system="clr-namespace:System;assembly=mscorlib">
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:converters="clr-namespace:MahApps.Metro.Converters">

<!-- ********************************** CheckBoxStyle ********************************** -->
<system:Double x:Key="CheckBoxBorderThemeThickness">2</system:Double>
<system:Double x:Key="CheckBoxCheckedStrokeThickness">0</system:Double>
<converters:CornerRadiusFilterConverter x:Key="CornerRadiusTopLeftConverter" Filter="TopLeft" />
<converters:CornerRadiusFilterConverter x:Key="CornerRadiusBottomRightConverter" Filter="BottomRight" />

<Style x:Key="MahApps.Styles.CheckBox" TargetType="CheckBox">
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.CheckBox.BackgroundUnchecked}" />
Expand Down Expand Up @@ -42,6 +45,8 @@
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
<Rectangle x:Name="NormalRectangle"
Fill="{TemplateBinding mah:CheckBoxHelper.CheckBackgroundFillUnchecked}"
RadiusX="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(mah:CheckBoxHelper.CheckCornerRadius), Mode=OneWay, Converter={StaticResource CornerRadiusTopLeftConverter}}"
RadiusY="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(mah:CheckBoxHelper.CheckCornerRadius), Mode=OneWay, Converter={StaticResource CornerRadiusBottomRightConverter}}"
Stroke="{TemplateBinding mah:CheckBoxHelper.CheckBackgroundStrokeUnchecked}"
StrokeThickness="{TemplateBinding mah:CheckBoxHelper.CheckStrokeThickness}"
UseLayoutRounding="False" />
Expand Down
4 changes: 3 additions & 1 deletion src/MahApps.Metro/Styles/Controls.ContextMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@
<Setter Property="VerticalContentAlignment" Value="Center" />
</Style>

<ContextMenu x:Key="MahApps.TextBox.ContextMenu" Style="{StaticResource MahApps.Styles.ContextMenu}" x:Shared="False">
<ContextMenu x:Key="MahApps.TextBox.ContextMenu"
x:Shared="False"
Style="{StaticResource MahApps.Styles.ContextMenu}">
<MenuItem Command="ApplicationCommands.Cut" Style="{DynamicResource MahApps.Styles.MenuItem}" />
<MenuItem Command="ApplicationCommands.Copy" Style="{DynamicResource MahApps.Styles.MenuItem}" />
<MenuItem Command="ApplicationCommands.Paste" Style="{DynamicResource MahApps.Styles.MenuItem}" />
Expand Down
7 changes: 4 additions & 3 deletions src/MahApps.Metro/Styles/Controls.MenuItem.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@
Margin="5 0 0 0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="{StaticResource Checkmark}"
Data="{DynamicResource Checkmark}"
Fill="{DynamicResource MahApps.Brushes.CheckmarkFill}"
FlowDirection="LeftToRight"
Visibility="Collapsed" />
Expand All @@ -377,7 +377,7 @@
<Path Grid.Column="5"
Margin="4 0 0 0"
VerticalAlignment="Center"
Data="{StaticResource RightArrow}"
Data="{DynamicResource RightArrow}"
Fill="{DynamicResource MahApps.Brushes.RightArrowFill}" />
</Grid>
<Grid Margin="2 0 1 0">
Expand Down Expand Up @@ -454,14 +454,15 @@
</Grid.ColumnDefinitions>
<ContentPresenter x:Name="Icon"
Margin="1"
HorizontalAlignment="Center"
VerticalAlignment="Center"
ContentSource="Icon"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
<Path x:Name="GlyphPanel"
Margin="5 0 0 0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Data="{StaticResource Checkmark}"
Data="{DynamicResource Checkmark}"
Fill="{DynamicResource MahApps.Brushes.CheckmarkFill}"
FlowDirection="LeftToRight"
Visibility="Collapsed" />
Expand Down
Loading

0 comments on commit 29a0ac4

Please sign in to comment.