Skip to content

Commit 29a0ac4

Browse files
committed
Merge branch 'develop' into main
2 parents 272e559 + 11afa2b commit 29a0ac4

21 files changed

+237
-47
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,8 @@ src/MahApps.Metro/Styles/Themes/*.xaml
264264
!src/MahApps.Metro/Styles/Themes/Theme.Template.xaml
265265

266266
# cake
267-
tools/
267+
tools/*
268+
!tools/packages.config
268269

269270
# XamlStyler
270271
!XamlStyler/

build.cake

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
// TOOLS / ADDINS
33
///////////////////////////////////////////////////////////////////////////////
44

5-
#module nuget:?package=Cake.DotNetTool.Module
6-
#tool "dotnet:?package=NuGetKeyVaultSignTool&version=1.2.28"
7-
#tool "dotnet:?package=AzureSignTool&version=2.0.17"
8-
9-
#tool GitVersion.CommandLine&version=5.5.1
10-
#tool gitreleasemanager
11-
#tool xunit.runner.console
12-
#tool vswhere
13-
#addin Cake.Figlet
5+
#module nuget:?package=Cake.DotNetTool.Module&version=0.5.0
6+
#tool dotnet:?package=NuGetKeyVaultSignTool&version=1.2.28
7+
#tool dotnet:?package=AzureSignTool&version=2.0.17
8+
#tool dotnet:?package=GitReleaseManager.Tool&version=0.11.0
9+
#tool dotnet:?package=GitVersion.Tool&version=5.6.6
10+
11+
#tool xunit.runner.console&version=2.4.1
12+
#tool vswhere&version=2.8.4
13+
#addin nuget:?package=Cake.Figlet&version=1.4.0
1414

1515
///////////////////////////////////////////////////////////////////////////////
1616
// ARGUMENTS

src/MahApps.Metro.Samples/MahApps.Metro.Demo/ExampleViews/ButtonsExample.xaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@
321321
</StackPanel.Resources>
322322

323323
<Label Content="CheckBox Win10" Style="{DynamicResource DescriptionHeaderStyle}" />
324-
<CheckBox IsChecked="False" IsEnabled="True" />
324+
<CheckBox IsChecked="False" IsEnabled="True" mah:CheckBoxHelper.CheckCornerRadius="2" />
325325
<CheckBox IsChecked="False" IsEnabled="False" />
326326
<CheckBox IsChecked="True" IsEnabled="False" />
327327
<CheckBox IsChecked="True" IsEnabled="True" />

src/MahApps.Metro/Behaviors/WindowsSettingBehavior.cs

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,14 @@ private void AssociatedObject_SourceInitialized(object sender, EventArgs e)
4747
window.Closed += this.AssociatedObject_Closed;
4848

4949
// This operation must be thread safe
50-
Application.Current?.BeginInvoke(() => Application.Current.SessionEnding += this.CurrentApplicationSessionEnding);
50+
window.BeginInvoke(() =>
51+
{
52+
var application = Application.Current;
53+
if (application != null)
54+
{
55+
application.SessionEnding += this.CurrentApplicationSessionEnding;
56+
}
57+
});
5158
}
5259

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

95102
// This operation must be thread safe
96-
Application.Current?.BeginInvoke(() => Application.Current.SessionEnding -= this.CurrentApplicationSessionEnding);
103+
window.BeginInvoke(() =>
104+
{
105+
var application = Application.Current;
106+
if (application != null)
107+
{
108+
application.SessionEnding -= this.CurrentApplicationSessionEnding;
109+
}
110+
});
97111
}
98112

99113
#pragma warning disable 618

src/MahApps.Metro/Controls/FlipView.cs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ namespace MahApps.Metro.Controls
2626
[TemplatePart(Name = PART_DownButton, Type = typeof(Button))]
2727
[TemplatePart(Name = PART_BannerGrid, Type = typeof(Grid))]
2828
[TemplatePart(Name = PART_BannerLabel, Type = typeof(Label))]
29+
[TemplatePart(Name = PART_Index, Type = typeof(ListBox))]
2930
[StyleTypedProperty(Property = nameof(NavigationButtonStyle), StyleTargetType = typeof(Button))]
3031
[StyleTypedProperty(Property = nameof(IndexItemContainerStyle), StyleTargetType = typeof(ListBoxItem))]
3132
public class FlipView : Selector
@@ -696,13 +697,15 @@ public string ButtonDownContentStringFormat
696697
private const string PART_ForwardButton = "PART_ForwardButton";
697698
private const string PART_Presenter = "PART_Presenter";
698699
private const string PART_UpButton = "PART_UpButton";
700+
private const string PART_Index = "PART_Index";
699701
/// <summary>
700702
/// To counteract the double Loaded event issue.
701703
/// </summary>
702704
private bool loaded;
703705
private bool allowSelectedIndexChangedCallback = true;
704706
private Grid bannerGrid;
705707
private Label bannerLabel;
708+
private ListBox indexListBox;
706709
private Button backButton;
707710
private Button forwardButton;
708711
private Button downButton;
@@ -859,6 +862,11 @@ public override void OnApplyTemplate()
859862

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

865+
if (this.indexListBox != null)
866+
{
867+
this.indexListBox.SelectionChanged -= OnIndexListBoxSelectionChanged;
868+
}
869+
862870
if (this.forwardButton != null)
863871
{
864872
this.forwardButton.Click -= this.NextButtonClick;
@@ -879,6 +887,8 @@ public override void OnApplyTemplate()
879887
this.downButton.Click -= this.NextButtonClick;
880888
}
881889

890+
this.indexListBox = this.GetTemplateChild(PART_Index) as ListBox;
891+
882892
this.forwardButton = this.GetTemplateChild(PART_ForwardButton) as Button;
883893
this.backButton = this.GetTemplateChild(PART_BackButton) as Button;
884894
this.upButton = this.GetTemplateChild(PART_UpButton) as Button;
@@ -911,6 +921,22 @@ public override void OnApplyTemplate()
911921
{
912922
this.bannerLabel.Opacity = this.IsBannerEnabled ? 1d : 0d;
913923
}
924+
925+
this.ExecuteWhenLoaded(() =>
926+
{
927+
if (this.indexListBox != null)
928+
{
929+
this.indexListBox.SelectionChanged += OnIndexListBoxSelectionChanged;
930+
}
931+
});
932+
}
933+
934+
private void OnIndexListBoxSelectionChanged(object sender, SelectionChangedEventArgs e)
935+
{
936+
if (ReferenceEquals(e.OriginalSource, this.indexListBox))
937+
{
938+
e.Handled = true;
939+
}
914940
}
915941

916942
protected override DependencyObject GetContainerForItemOverride()

src/MahApps.Metro/Controls/Helper/CheckBoxHelper.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,36 @@ public static void SetCheckSize(DependencyObject obj, double value)
3838
obj.SetValue(CheckSizeProperty, value);
3939
}
4040

41+
public static readonly DependencyProperty CheckCornerRadiusProperty
42+
= DependencyProperty.RegisterAttached(
43+
"CheckCornerRadius",
44+
typeof(CornerRadius),
45+
typeof(CheckBoxHelper),
46+
new FrameworkPropertyMetadata(
47+
new CornerRadius(),
48+
FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));
49+
50+
/// <summary>
51+
/// Gets the CornerRadius of the CheckBox itself.
52+
/// The CheckCornerRadius property allows users to control the roundness of the CheckBox corners independently by setting a radius value for each corner.
53+
/// </summary>
54+
[Category(AppName.MahApps)]
55+
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
56+
public static CornerRadius GetCheckCornerRadius(UIElement element)
57+
{
58+
return (CornerRadius)element.GetValue(CheckCornerRadiusProperty);
59+
}
60+
61+
/// <summary>
62+
/// Sets the CornerRadius of the CheckBox itself.
63+
/// </summary>
64+
[Category(AppName.MahApps)]
65+
[AttachedPropertyBrowsableForType(typeof(CheckBox))]
66+
public static void SetCheckCornerRadius(UIElement element, CornerRadius value)
67+
{
68+
element.SetValue(CheckCornerRadiusProperty, value);
69+
}
70+
4171
public static readonly DependencyProperty CheckStrokeThicknessProperty
4272
= DependencyProperty.RegisterAttached(
4373
"CheckStrokeThickness",

src/MahApps.Metro/Controls/Helper/TextBoxHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -931,11 +931,11 @@ public static void ButtonClicked(object sender, RoutedEventArgs e)
931931
{
932932
if (comboBox.IsEditable)
933933
{
934-
comboBox.Text = string.Empty;
934+
comboBox.SetCurrentValue(ComboBox.TextProperty, string.Empty);
935935
comboBox.GetBindingExpression(ComboBox.TextProperty)?.UpdateSource();
936936
}
937937

938-
comboBox.SelectedItem = null;
938+
comboBox.SetCurrentValue(ComboBox.SelectedItemProperty, null);
939939
comboBox.GetBindingExpression(ComboBox.SelectedItemProperty)?.UpdateSource();
940940
}
941941
else if (parent is ColorPickerBase colorPicker)
@@ -1020,4 +1020,4 @@ private static void ComboBoxLoaded(object sender, RoutedEventArgs e)
10201020
}
10211021
}
10221022
}
1023-
}
1023+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
using System;
2+
using System.Globalization;
3+
using System.Windows.Data;
4+
using System.Windows.Media;
5+
using JetBrains.Annotations;
6+
7+
namespace MahApps.Metro.Converters
8+
{
9+
/// <summary>
10+
/// Converts a given <see cref="Color"/> into a <see cref="SolidColorBrush"/>.
11+
/// </summary>
12+
[ValueConversion(typeof(Color), typeof(SolidColorBrush))]
13+
public class ColorToSolidColorBrushConverter : IValueConverter
14+
{
15+
private static ColorToSolidColorBrushConverter defaultInstance;
16+
17+
/// <summary>
18+
/// Gets a static instance of the converter if needed.
19+
/// </summary>
20+
public static ColorToSolidColorBrushConverter DefaultInstance => defaultInstance ??= new ColorToSolidColorBrushConverter();
21+
22+
/// <summary>
23+
/// Gets or Sets the brush which will be used if the conversion fails.
24+
/// </summary>
25+
[CanBeNull]
26+
public SolidColorBrush FallbackBrush { get; set; }
27+
28+
/// <summary>
29+
/// Gets or Sets the color which will be used if the conversion fails.
30+
/// </summary>
31+
[CanBeNull]
32+
public Color? FallbackColor { get; set; }
33+
34+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
35+
{
36+
if (value is Color color)
37+
{
38+
var brush = new SolidColorBrush(color);
39+
brush.Freeze();
40+
return brush;
41+
}
42+
43+
return this.FallbackBrush;
44+
}
45+
46+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
47+
{
48+
return value is SolidColorBrush brush ? brush.Color : this.FallbackColor;
49+
}
50+
}
51+
}
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
// See the LICENSE file in the project root for more information.
4+
5+
using System;
6+
using System.Globalization;
7+
using System.Windows;
8+
using System.Windows.Data;
9+
10+
namespace MahApps.Metro.Converters
11+
{
12+
/// <summary>
13+
/// Filters a CornerRadius by the given Filter property. Result can be a new CornerRadius or a value of it's 4 corners.
14+
/// </summary>
15+
public class CornerRadiusFilterConverter : IValueConverter
16+
{
17+
public RadiusType Filter { get; set; } = RadiusType.None;
18+
19+
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
20+
{
21+
if (value is CornerRadius cornerRadius)
22+
{
23+
var filter = this.Filter;
24+
25+
// yes, we can override it with the parameter value
26+
if (parameter is RadiusType radiusType)
27+
{
28+
filter = radiusType;
29+
}
30+
31+
switch (filter)
32+
{
33+
default:
34+
return cornerRadius;
35+
case RadiusType.Left:
36+
return new CornerRadius(cornerRadius.TopLeft, 0, 0, cornerRadius.BottomLeft);
37+
case RadiusType.Top:
38+
return new CornerRadius(cornerRadius.TopLeft, cornerRadius.TopRight, 0, 0);
39+
case RadiusType.Right:
40+
return new CornerRadius(0, cornerRadius.TopRight, cornerRadius.BottomRight, 0);
41+
case RadiusType.Bottom:
42+
return new CornerRadius(0, 0, cornerRadius.BottomRight, cornerRadius.BottomLeft);
43+
case RadiusType.TopLeft:
44+
return cornerRadius.TopLeft;
45+
case RadiusType.TopRight:
46+
return cornerRadius.TopRight;
47+
case RadiusType.BottomRight:
48+
return cornerRadius.BottomRight;
49+
case RadiusType.BottomLeft:
50+
return cornerRadius.BottomLeft;
51+
}
52+
}
53+
54+
return Binding.DoNothing;
55+
}
56+
57+
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
58+
{
59+
// for now no back converting
60+
return DependencyProperty.UnsetValue;
61+
}
62+
}
63+
}

src/MahApps.Metro/Styles/Controls.CheckBox.xaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:mah="clr-namespace:MahApps.Metro.Controls"
4-
xmlns:system="clr-namespace:System;assembly=mscorlib">
4+
xmlns:system="clr-namespace:System;assembly=mscorlib"
5+
xmlns:converters="clr-namespace:MahApps.Metro.Converters">
56

67
<!-- ********************************** CheckBoxStyle ********************************** -->
78
<system:Double x:Key="CheckBoxBorderThemeThickness">2</system:Double>
89
<system:Double x:Key="CheckBoxCheckedStrokeThickness">0</system:Double>
10+
<converters:CornerRadiusFilterConverter x:Key="CornerRadiusTopLeftConverter" Filter="TopLeft" />
11+
<converters:CornerRadiusFilterConverter x:Key="CornerRadiusBottomRightConverter" Filter="BottomRight" />
912

1013
<Style x:Key="MahApps.Styles.CheckBox" TargetType="CheckBox">
1114
<Setter Property="Background" Value="{DynamicResource MahApps.Brushes.CheckBox.BackgroundUnchecked}" />
@@ -42,6 +45,8 @@
4245
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
4346
<Rectangle x:Name="NormalRectangle"
4447
Fill="{TemplateBinding mah:CheckBoxHelper.CheckBackgroundFillUnchecked}"
48+
RadiusX="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(mah:CheckBoxHelper.CheckCornerRadius), Mode=OneWay, Converter={StaticResource CornerRadiusTopLeftConverter}}"
49+
RadiusY="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(mah:CheckBoxHelper.CheckCornerRadius), Mode=OneWay, Converter={StaticResource CornerRadiusBottomRightConverter}}"
4550
Stroke="{TemplateBinding mah:CheckBoxHelper.CheckBackgroundStrokeUnchecked}"
4651
StrokeThickness="{TemplateBinding mah:CheckBoxHelper.CheckStrokeThickness}"
4752
UseLayoutRounding="False" />

0 commit comments

Comments
 (0)