Skip to content

Commit badc72e

Browse files
authored
Code clean up (#2283)
1 parent 3b50938 commit badc72e

File tree

12 files changed

+65
-97
lines changed

12 files changed

+65
-97
lines changed

MainDemo.Wpf/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace MaterialDesignDemo
1313
{
1414
public partial class MainWindow
1515
{
16-
public static Snackbar Snackbar = new Snackbar();
16+
public static Snackbar Snackbar = new();
1717
public MainWindow()
1818
{
1919
InitializeComponent();

MaterialDesignColors.Wpf/ColorManipulation/Lab.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal class LabConstants
2424
public const double WhitePointY = 1;
2525
public const double WhitePointZ = 1.08883;
2626

27-
public static double eCubedRoot = Math.Pow(e, 1.0 / 3);
27+
public static readonly double eCubedRoot = Math.Pow(e, 1.0 / 3);
2828
public const double k = 24389 / 27.0;
2929
public const double e = 216 / 24389.0;
3030
}

MaterialDesignThemes.Wpf/Clock.cs

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public class Clock : Control
4747
public const string MinutesVisualStateName = "Minutes";
4848
public const string SecondsVisualStateName = "Seconds";
4949

50-
private Point _centreCanvas = new Point(0, 0);
51-
private Point _currentStartPosition = new Point(0, 0);
50+
private Point _centreCanvas = new(0, 0);
51+
private Point _currentStartPosition = new(0, 0);
5252
private TextBlock? _hourReadOutPartName;
5353
private TextBlock? _minuteReadOutPartName;
5454
private TextBlock? _secondReadOutPartName;
@@ -130,9 +130,7 @@ public bool IsPostMeridiem
130130
nameof(Is24Hours), typeof(bool), typeof(Clock), new PropertyMetadata(default(bool), Is24HoursChanged));
131131

132132
private static void Is24HoursChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
133-
{
134-
((Clock)d).GenerateButtons();
135-
}
133+
=> ((Clock)d).GenerateButtons();
136134

137135
public bool Is24Hours
138136
{
@@ -309,7 +307,7 @@ private void GenerateButtons()
309307
ClockDisplayMode.Seconds);
310308
}
311309

312-
void RemoveExistingButtons(Canvas canvas)
310+
static void RemoveExistingButtons(Canvas canvas)
313311
{
314312
for (int i = canvas.Children.Count - 1; i >= 0; i--)
315313
{
@@ -322,22 +320,22 @@ void RemoveExistingButtons(Canvas canvas)
322320
}
323321

324322
private void SecondReadOutPartNameOnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
325-
{
326-
SetCurrentValue(Clock.DisplayModeProperty, ClockDisplayMode.Seconds);
327-
}
323+
=> SetCurrentValue(DisplayModeProperty, ClockDisplayMode.Seconds);
328324

329325
private void MinuteReadOutPartNameOnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
330-
{
331-
SetCurrentValue(Clock.DisplayModeProperty, ClockDisplayMode.Minutes);
332-
}
326+
=> SetCurrentValue(DisplayModeProperty, ClockDisplayMode.Minutes);
333327

334328
private void HourReadOutPartNameOnPreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs mouseButtonEventArgs)
335-
{
336-
SetCurrentValue(Clock.DisplayModeProperty, ClockDisplayMode.Hours);
337-
}
338-
339-
private void GenerateButtons(Panel canvas, ICollection<int> range, double radiusRatio, IValueConverter isCheckedConverter, Func<int, string> stylePropertySelector,
340-
string format, ClockDisplayMode clockDisplayMode)
329+
=> SetCurrentValue(DisplayModeProperty, ClockDisplayMode.Hours);
330+
331+
private void GenerateButtons(
332+
Panel canvas,
333+
ICollection<int> range,
334+
double radiusRatio,
335+
IValueConverter isCheckedConverter,
336+
Func<int, string> stylePropertySelector,
337+
string format,
338+
ClockDisplayMode clockDisplayMode)
341339
{
342340
var anglePerItem = 360.0 / range.Count;
343341
var radiansPerItem = anglePerItem * (Math.PI / 180);
@@ -366,6 +364,20 @@ private void GenerateButtons(Panel canvas, ICollection<int> range, double radius
366364
button.Content = (i == 60 ? 0 : (i == 24 && clockDisplayMode == ClockDisplayMode.Hours ? 0 : i)).ToString(format);
367365
canvas.Children.Add(button);
368366
}
367+
368+
BindingBase GetBinding(
369+
string propertyName,
370+
object? owner = null,
371+
IValueConverter? converter = null,
372+
object? converterParameter = null)
373+
{
374+
return new Binding(propertyName)
375+
{
376+
Source = owner ?? this,
377+
Converter = converter,
378+
ConverterParameter = converterParameter
379+
};
380+
}
369381
}
370382

371383

@@ -404,9 +416,7 @@ private void ClockItemDragCompletedHandler(object sender, DragCompletedEventArgs
404416
}
405417

406418
private void ClockItemDragStartedHandler(object sender, DragStartedEventArgs dragStartedEventArgs)
407-
{
408-
_currentStartPosition = new Point(dragStartedEventArgs.HorizontalOffset, dragStartedEventArgs.VerticalOffset);
409-
}
419+
=> _currentStartPosition = new Point(dragStartedEventArgs.HorizontalOffset, dragStartedEventArgs.VerticalOffset);
410420

411421
private void ClockItemDragDeltaHandler(object sender, DragDeltaEventArgs dragDeltaEventArgs)
412422
{
@@ -455,15 +465,5 @@ private static void SetFlags(Clock clock)
455465
clock.IsMidnightHour = clock.Time.Hour == 0;
456466
clock.IsMiddayHour = clock.Time.Hour == 12;
457467
}
458-
459-
private BindingBase GetBinding(
460-
string propertyName,
461-
object? owner = null,
462-
IValueConverter? converter = null,
463-
object? converterParameter = null)
464-
{
465-
var result = new Binding(propertyName) { Source = owner ?? this, Converter = converter, ConverterParameter = converterParameter };
466-
return result;
467-
}
468468
}
469469
}

MaterialDesignThemes.Wpf/Converters/ClockItemIsCheckedConverter.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public object Convert(object value, Type targetType, object parameter, CultureIn
2222
var dateTime = (DateTime)value;
2323
var i = (int)parameter;
2424

25-
int converted = 0;
25+
int converted;
2626
if (_displayMode == ClockDisplayMode.Hours)
2727
converted = MassageHour(dateTime.Hour, _is24Hours);
2828
else if (_displayMode == ClockDisplayMode.Minutes)
@@ -58,9 +58,7 @@ private static int MassageHour(int val, bool is24Hours)
5858
}
5959

6060
private static int MassageMinuteSecond(int val)
61-
{
62-
return val == 0 ? 60 : val;
63-
}
61+
=> val == 0 ? 60 : val;
6462

6563
private static int ReverseMassageHour(int val, DateTime currentTime, bool is24Hours)
6664
{
@@ -75,8 +73,6 @@ private static int ReverseMassageHour(int val, DateTime currentTime, bool is24Ho
7573
}
7674

7775
private static int ReverseMassageMinuteSecond(int val)
78-
{
79-
return val == 60 ? 0 : val;
80-
}
76+
=> val == 60 ? 0 : val;
8177
}
8278
}

MaterialDesignThemes.Wpf/DialogHost.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ public class DialogHost : ContentControl
4949
/// <summary>
5050
/// Routed command to be used somewhere inside an instance to trigger showing of the dialog. Content can be passed to the dialog via a <see cref="Button.CommandParameter"/>.
5151
/// </summary>
52-
public static RoutedCommand OpenDialogCommand = new RoutedCommand();
52+
public static readonly RoutedCommand OpenDialogCommand = new();
5353
/// <summary>
5454
/// Routed command to be used inside dialog content to close a dialog. Use a <see cref="Button.CommandParameter"/> to indicate the result of the parameter.
5555
/// </summary>
56-
public static RoutedCommand CloseDialogCommand = new RoutedCommand();
56+
public static readonly RoutedCommand CloseDialogCommand = new();
5757

58-
private static readonly HashSet<DialogHost> LoadedInstances = new HashSet<DialogHost>();
58+
private static readonly HashSet<DialogHost> LoadedInstances = new();
5959

6060
private DialogOpenedEventHandler? _asyncShowOpenedEventHandler;
6161
private DialogClosingEventHandler? _asyncShowClosingEventHandler;

MaterialDesignThemes.Wpf/DrawerHost.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public class DrawerHost : ContentControl
4747
public const string TemplateRightDrawerPartName = "PART_RightDrawer";
4848
public const string TemplateBottomDrawerPartName = "PART_BottomDrawer";
4949

50-
public static RoutedCommand OpenDrawerCommand = new RoutedCommand();
51-
public static RoutedCommand CloseDrawerCommand = new RoutedCommand();
50+
public static readonly RoutedCommand OpenDrawerCommand = new();
51+
public static readonly RoutedCommand CloseDrawerCommand = new();
5252

5353
private FrameworkElement? _templateContentCoverElement;
5454
private FrameworkElement? _leftDrawerElement;

MaterialDesignThemes.Wpf/Flipper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace MaterialDesignThemes.Wpf
1111
[TemplateVisualState(GroupName = TemplateFlipGroupName, Name = TemplateUnflippedStateName)]
1212
public class Flipper : Control
1313
{
14-
public static RoutedCommand FlipCommand = new RoutedCommand();
14+
public static readonly RoutedCommand FlipCommand = new();
1515

1616
public const string Plane3DPartName = "PART_Plane3D";
1717
public const string TemplateFlipGroupName = "FlipStates";

MaterialDesignThemes.Wpf/PopupBox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ public class PopupBox : ContentControl
106106
/// <summary>
107107
/// Routed command to be used inside of a popup content to close it.
108108
/// </summary>
109-
public static RoutedCommand ClosePopupCommand = new RoutedCommand();
109+
public static readonly RoutedCommand ClosePopupCommand = new();
110110

111111
private PopupEx? _popup;
112112
private ContentControl? _popupContentControl;

MaterialDesignThemes.Wpf/RatingBar.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ namespace MaterialDesignThemes.Wpf
1111
/// </summary>
1212
public class RatingBar : Control
1313
{
14-
public static RoutedCommand SelectRatingCommand = new RoutedCommand();
14+
public static readonly RoutedCommand SelectRatingCommand = new();
1515

1616
static RatingBar()
1717
{
Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
using System;
2-
using System.Windows;
1+
using System.Windows;
32
using System.Windows.Controls.Primitives;
43
using System.Windows.Media;
54

65
namespace MaterialDesignThemes.Wpf
76
{
87
public static class ToggleButtonAssist
98
{
10-
119
private static readonly DependencyPropertyKey HasOnContentPropertyKey =
1210
DependencyProperty.RegisterAttachedReadOnly(
1311
"HasOnContent", typeof(bool), typeof(ToggleButtonAssist),
@@ -16,19 +14,15 @@ public static class ToggleButtonAssist
1614
public static readonly DependencyProperty HasOnContentProperty = HasOnContentPropertyKey.DependencyProperty;
1715

1816
private static void SetHasOnContent(DependencyObject element, object value)
19-
{
20-
element.SetValue(HasOnContentPropertyKey, value);
21-
}
17+
=> element.SetValue(HasOnContentPropertyKey, value);
2218

2319
/// <summary>
2420
/// Framework use only.
2521
/// </summary>
2622
/// <param name="element"></param>
2723
/// <returns></returns>
2824
public static bool GetHasOnContent(DependencyObject element)
29-
{
30-
return (bool)element.GetValue(HasOnContentProperty);
31-
}
25+
=> (bool)element.GetValue(HasOnContentProperty);
3226

3327
/// <summary>
3428
/// Allows on (IsChecked) content to be provided on supporting <see cref="ToggleButton"/> styles.
@@ -37,27 +31,21 @@ public static bool GetHasOnContent(DependencyObject element)
3731
"OnContent", typeof(object), typeof(ToggleButtonAssist), new PropertyMetadata(default(object), OnContentPropertyChangedCallback));
3832

3933
private static void OnContentPropertyChangedCallback(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs dependencyPropertyChangedEventArgs)
40-
{
41-
SetHasOnContent(dependencyObject, dependencyPropertyChangedEventArgs.NewValue != null);
42-
}
34+
=> SetHasOnContent(dependencyObject, dependencyPropertyChangedEventArgs.NewValue != null);
4335

4436
/// <summary>
4537
/// Allows on (IsChecked) content to be provided on supporting <see cref="ToggleButton"/> styles.
4638
/// </summary>
4739
/// <param name="element"></param>
4840
/// <param name="value"></param>
4941
public static void SetOnContent(DependencyObject element, object value)
50-
{
51-
element.SetValue(OnContentProperty, value);
52-
}
42+
=> element.SetValue(OnContentProperty, value);
5343

5444
/// <summary>
5545
/// Allows on (IsChecked) content to be provided on supporting <see cref="ToggleButton"/> styles.
5646
/// </summary>
5747
public static object GetOnContent(DependencyObject element)
58-
{
59-
return (object)element.GetValue(OnContentProperty);
60-
}
48+
=> element.GetValue(OnContentProperty);
6149

6250
/// <summary>
6351
/// Allows an on (IsChecked) template to be provided on supporting <see cref="ToggleButton"/> styles.
@@ -69,44 +57,32 @@ public static object GetOnContent(DependencyObject element)
6957
/// Allows an on (IsChecked) template to be provided on supporting <see cref="ToggleButton"/> styles.
7058
/// </summary>
7159
public static void SetOnContentTemplate(DependencyObject element, DataTemplate value)
72-
{
73-
element.SetValue(OnContentTemplateProperty, value);
74-
}
60+
=> element.SetValue(OnContentTemplateProperty, value);
7561

7662
/// <summary>
7763
/// Allows an on (IsChecked) template to be provided on supporting <see cref="ToggleButton"/> styles.
7864
/// </summary>
7965
public static DataTemplate GetOnContentTemplate(DependencyObject element)
80-
{
81-
return (DataTemplate)element.GetValue(OnContentTemplateProperty);
82-
}
66+
=> (DataTemplate)element.GetValue(OnContentTemplateProperty);
8367

84-
public static DependencyProperty SwitchTrackOnBackgroundProperty =
68+
public static readonly DependencyProperty SwitchTrackOnBackgroundProperty =
8569
DependencyProperty.RegisterAttached(
8670
"SwitchTrackOnBackground", typeof(SolidColorBrush), typeof(ToggleButtonAssist));
8771

8872
public static void SetSwitchTrackOnBackground(DependencyObject element, SolidColorBrush value)
89-
{
90-
element.SetValue(SwitchTrackOnBackgroundProperty, value);
91-
}
73+
=> element.SetValue(SwitchTrackOnBackgroundProperty, value);
9274

9375
public static SolidColorBrush GetSwitchTrackOnBackground(DependencyObject element)
94-
{
95-
return (SolidColorBrush)element.GetValue(SwitchTrackOnBackgroundProperty);
96-
}
76+
=> (SolidColorBrush)element.GetValue(SwitchTrackOnBackgroundProperty);
9777

98-
public static DependencyProperty SwitchTrackOffBackgroundProperty =
78+
public static readonly DependencyProperty SwitchTrackOffBackgroundProperty =
9979
DependencyProperty.RegisterAttached(
10080
"SwitchTrackOffBackground", typeof(SolidColorBrush), typeof(ToggleButtonAssist));
10181

10282
public static void SetSwitchTrackOffBackground(DependencyObject element, SolidColorBrush value)
103-
{
104-
element.SetValue(SwitchTrackOffBackgroundProperty, value);
105-
}
83+
=> element.SetValue(SwitchTrackOffBackgroundProperty, value);
10684

10785
public static SolidColorBrush GetSwitchTrackOffBackground(DependencyObject element)
108-
{
109-
return (SolidColorBrush)element.GetValue(SwitchTrackOffBackgroundProperty);
110-
}
86+
=> (SolidColorBrush)element.GetValue(SwitchTrackOffBackgroundProperty);
11187
}
11288
}

0 commit comments

Comments
 (0)