From c64e7e28410140ad49d57dbab8a9b8a70ce1e0ab Mon Sep 17 00:00:00 2001 From: SKProCH Date: Sun, 8 Sep 2024 00:58:59 +0300 Subject: [PATCH] Add nullability to many places in Material.Avalonia.Dialogs, resolves a lot of warnings, some unnecessary code cleanup --- Material.Avalonia.Demo.Browser/Program.cs | 7 ++-- Material.Avalonia.Demo.Desktop/Program.cs | 3 +- Material.Avalonia.Demo/App.axaml | 2 -- Material.Avalonia.Demo/MainView.axaml | 3 +- Material.Avalonia.Demo/MainView.axaml.cs | 3 -- .../Pages/SideSheetDemo.axaml.cs | 8 ----- .../Pages/SnackbarDemo.axaml | 2 +- .../Pages/SnackbarDemo.axaml.cs | 2 +- .../Pages/TogglesDemo.axaml | 2 +- .../ViewModels/RelayCommand.cs | 2 +- .../Bases/DialogWindowBase.cs | 4 +-- .../Bases/DialogWindowBuilderParamsBase.cs | 10 +++--- .../Commands/MaterialDialogRelayCommand.cs | 17 +++++----- .../Converters/StringToTransformConverter.cs | 8 ++--- .../CustomDialogBuilderParams.cs | 4 +-- .../DateTimePickerDialogResult.cs | 8 ++--- Material.Avalonia.Dialogs/DialogResult.cs | 4 +-- Material.Avalonia.Dialogs/Icons/DialogIcon.cs | 13 +++---- .../Interfaces/IDialogResult.cs | 2 +- .../Resources/TemplateResources.axaml.cs | 2 +- .../TextFieldBuilderParams.cs | 10 +++--- .../TextFieldDialogResult.cs | 15 ++++---- Material.Avalonia.Dialogs/TextFieldResult.cs | 2 +- .../ViewModels/CustomDialogViewModel.cs | 8 ++--- .../ViewModels/DatePickerDialogViewModel.cs | 11 +++--- .../ViewModels/DialogWindowViewModel.cs | 8 ++--- .../Elements/DialogButtonViewModel.cs | 4 +-- .../Elements/ObsoleteDialogButtonViewModel.cs | 4 +-- .../Elements/TextField/TextFieldViewModel.cs | 34 +++++++++---------- .../ViewModels/TextFieldDialogViewModel.cs | 10 +++--- .../ViewModels/TimePickerDialogViewModel.cs | 8 ++--- .../ViewModels/ViewModelBase.cs | 4 +-- .../Views/DatePickerDialog.axaml.cs | 2 +- .../Views/TextFieldDialog.axaml.cs | 2 +- .../Views/TimePickerDialog.axaml.cs | 2 +- .../Controls/CircleClockPicker.axaml.cs | 4 +-- .../Internal/LightweightObservableBase.cs | 2 +- .../Resources/Themes/CaptionButtons.xaml | 2 +- .../Resources/Themes/MenuItem.axaml | 3 +- .../Resources/Themes/RefreshContainer.xaml | 3 +- Material.Styles/Themes/Base/BaseThemeMode.cs | 2 +- 41 files changed, 113 insertions(+), 133 deletions(-) diff --git a/Material.Avalonia.Demo.Browser/Program.cs b/Material.Avalonia.Demo.Browser/Program.cs index 6aedcc92..bfb8a6b7 100644 --- a/Material.Avalonia.Demo.Browser/Program.cs +++ b/Material.Avalonia.Demo.Browser/Program.cs @@ -2,14 +2,15 @@ using System.Threading.Tasks; using Avalonia; using Avalonia.Browser; -using Material.Avalonia.Demo; using ShowMeTheXaml; [assembly: SupportedOSPlatform("browser")] -internal sealed partial class Program +namespace Material.Avalonia.Demo.Browser; + +internal static class Program { - private static Task Main(string[] args) => BuildAvaloniaApp() + private static Task Main() => BuildAvaloniaApp() .StartBrowserAppAsync("out"); public static AppBuilder BuildAvaloniaApp() diff --git a/Material.Avalonia.Demo.Desktop/Program.cs b/Material.Avalonia.Demo.Desktop/Program.cs index f5eef1d3..fda6e21a 100644 --- a/Material.Avalonia.Demo.Desktop/Program.cs +++ b/Material.Avalonia.Demo.Desktop/Program.cs @@ -1,9 +1,8 @@ using System; using Avalonia; -using Material.Avalonia.Demo; using ShowMeTheXaml; -namespace Material.Demo { +namespace Material.Avalonia.Demo.Desktop { internal class Program { // Initialization code. Don't use any Avalonia, third-party APIs or any // SynchronizationContext-reliant code before AppMain is called: things aren't initialized diff --git a/Material.Avalonia.Demo/App.axaml b/Material.Avalonia.Demo/App.axaml index 00cfa2d6..fafb075d 100644 --- a/Material.Avalonia.Demo/App.axaml +++ b/Material.Avalonia.Demo/App.axaml @@ -1,11 +1,9 @@  fonts:Inter#Inter, $Default diff --git a/Material.Avalonia.Demo/MainView.axaml b/Material.Avalonia.Demo/MainView.axaml index 05ee5dd7..46e8c766 100644 --- a/Material.Avalonia.Demo/MainView.axaml +++ b/Material.Avalonia.Demo/MainView.axaml @@ -7,7 +7,6 @@ xmlns:dialogHostAvalonia="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia" xmlns:models="clr-namespace:Material.Avalonia.Demo.Models" xmlns:pages="clr-namespace:Material.Avalonia.Demo.Pages" - xmlns:pages1="clr-namespace:Material.Demo.Pages" mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" x:Class="Material.Avalonia.Demo.MainView"> @@ -191,7 +190,7 @@ - + diff --git a/Material.Avalonia.Demo/MainView.axaml.cs b/Material.Avalonia.Demo/MainView.axaml.cs index f2e96865..ae9dea16 100644 --- a/Material.Avalonia.Demo/MainView.axaml.cs +++ b/Material.Avalonia.Demo/MainView.axaml.cs @@ -5,7 +5,6 @@ using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Interactivity; -using Avalonia.Markup.Xaml; using Avalonia.Threading; using Material.Styles.Controls; using Material.Styles.Models; @@ -15,8 +14,6 @@ namespace Material.Avalonia.Demo; public partial class MainView : UserControl { - private readonly List helloSnackBars = new(); - public MainView() { InitializeComponent(); DrawerList.PointerReleased += DrawerSelectionChanged; diff --git a/Material.Avalonia.Demo/Pages/SideSheetDemo.axaml.cs b/Material.Avalonia.Demo/Pages/SideSheetDemo.axaml.cs index 09b16795..3218d15f 100644 --- a/Material.Avalonia.Demo/Pages/SideSheetDemo.axaml.cs +++ b/Material.Avalonia.Demo/Pages/SideSheetDemo.axaml.cs @@ -9,14 +9,6 @@ public SideSheetDemo() { InitializeComponent(); } - private void CloseSideInfoButton_OnClick(object? sender, RoutedEventArgs e) { - var vm = DataContext as SideSheetDemoViewModel; - if (vm == null) - return; - - vm.SideInfoOpened = false; - } - private void OpenSideInfoButton_OnClick(object? sender, RoutedEventArgs e) { var vm = DataContext as SideSheetDemoViewModel; if (vm == null) diff --git a/Material.Avalonia.Demo/Pages/SnackbarDemo.axaml b/Material.Avalonia.Demo/Pages/SnackbarDemo.axaml index 47f7119b..acb337a8 100644 --- a/Material.Avalonia.Demo/Pages/SnackbarDemo.axaml +++ b/Material.Avalonia.Demo/Pages/SnackbarDemo.axaml @@ -6,7 +6,7 @@ xmlns:controls="clr-namespace:Material.Styles.Controls;assembly=Material.Styles" xmlns:dialogHost="clr-namespace:DialogHostAvalonia;assembly=DialogHost.Avalonia" xmlns:showMeTheXaml="clr-namespace:ShowMeTheXaml;assembly=ShowMeTheXaml.Avalonia" - x:Class="Material.Demo.Pages.SnackbarDemo"> + x:Class="Material.Avalonia.Demo.Pages.SnackbarDemo"> diff --git a/Material.Avalonia.Demo/Pages/SnackbarDemo.axaml.cs b/Material.Avalonia.Demo/Pages/SnackbarDemo.axaml.cs index c860ac70..aa0e48ad 100644 --- a/Material.Avalonia.Demo/Pages/SnackbarDemo.axaml.cs +++ b/Material.Avalonia.Demo/Pages/SnackbarDemo.axaml.cs @@ -5,7 +5,7 @@ using Material.Styles.Controls; using Material.Styles.Models; -namespace Material.Demo.Pages; +namespace Material.Avalonia.Demo.Pages; public partial class SnackbarDemo : UserControl { private int _actionCount; diff --git a/Material.Avalonia.Demo/Pages/TogglesDemo.axaml b/Material.Avalonia.Demo/Pages/TogglesDemo.axaml index d6f3012b..57f6cd56 100644 --- a/Material.Avalonia.Demo/Pages/TogglesDemo.axaml +++ b/Material.Avalonia.Demo/Pages/TogglesDemo.axaml @@ -241,7 +241,7 @@ Button's ControlThemes if you don't want pressed state: - + diff --git a/Material.Avalonia.Demo/ViewModels/RelayCommand.cs b/Material.Avalonia.Demo/ViewModels/RelayCommand.cs index 3900573e..56b63f32 100644 --- a/Material.Avalonia.Demo/ViewModels/RelayCommand.cs +++ b/Material.Avalonia.Demo/ViewModels/RelayCommand.cs @@ -33,7 +33,7 @@ public void RaiseCanExecute() { if (handler != null) { // Call CanExecute via Dispatcher.UIThread.Post to prevent CanExecute can't be called from other thread. - Dispatcher.UIThread.Post(delegate { handler?.Invoke(this, new EventArgs()); }); + Dispatcher.UIThread.Post(delegate { handler.Invoke(this, EventArgs.Empty); }); } } } \ No newline at end of file diff --git a/Material.Avalonia.Dialogs/Bases/DialogWindowBase.cs b/Material.Avalonia.Dialogs/Bases/DialogWindowBase.cs index ea3023c2..67366ab9 100644 --- a/Material.Avalonia.Dialogs/Bases/DialogWindowBase.cs +++ b/Material.Avalonia.Dialogs/Bases/DialogWindowBase.cs @@ -20,7 +20,7 @@ public DialogWindowBase(TWindow window) /// Get window content. It most used for show dialog from other places. /// /// The content of dialog window. - public object GetContent() => _window.Content; + public object GetContent() => _window.Content!; /// /// Get window itself. @@ -52,7 +52,7 @@ private Task Procedure(Action action) { var tcs = new TaskCompletionSource(); - void OnceHandler(object sender, EventArgs args) + void OnceHandler(object? sender, EventArgs args) { tcs.TrySetResult(_window.GetResult()); _window.Closed -= OnceHandler; diff --git a/Material.Avalonia.Dialogs/Bases/DialogWindowBuilderParamsBase.cs b/Material.Avalonia.Dialogs/Bases/DialogWindowBuilderParamsBase.cs index 3e9242ad..f782f575 100644 --- a/Material.Avalonia.Dialogs/Bases/DialogWindowBuilderParamsBase.cs +++ b/Material.Avalonia.Dialogs/Bases/DialogWindowBuilderParamsBase.cs @@ -9,8 +9,8 @@ public class DialogWindowBuilderParamsBase public string WindowTitle = "Warning"; public double? MaxWidth = null; public double? Width = null; - public string ContentHeader = null; - public string SupportingText = null; + public string? ContentHeader = null; + public string? SupportingText = null; public bool Borderless = false; public WindowStartupLocation StartupLocation = WindowStartupLocation.CenterScreen; @@ -24,19 +24,19 @@ public class DialogWindowBuilderParamsBase /// /// Specify , or for dialog header icon. /// - public object DialogIcon = null; + public object? DialogIcon = null; /// /// Build dialog buttons stack (left side). ///
You can use for create buttons stack in easy way. ///
- public DialogButton[] NeutralDialogButtons; + public DialogButton[]? NeutralDialogButtons; /// /// Build dialog buttons stack. ///
You can use for create buttons stack in easy way. ///
- public DialogButton[] DialogButtons; + public DialogButton[]? DialogButtons; /// /// Define result after close the dialog not from buttons diff --git a/Material.Avalonia.Dialogs/Commands/MaterialDialogRelayCommand.cs b/Material.Avalonia.Dialogs/Commands/MaterialDialogRelayCommand.cs index 4e377b52..ae381224 100644 --- a/Material.Avalonia.Dialogs/Commands/MaterialDialogRelayCommand.cs +++ b/Material.Avalonia.Dialogs/Commands/MaterialDialogRelayCommand.cs @@ -8,21 +8,20 @@ namespace Material.Dialog.Commands { /// If you want to use this one, you should copy all whole code and paste them to your new RelayCommand.cs source file. /// public class MaterialDialogRelayCommand : ICommand { - private readonly Func canExecute; - private readonly Action execute; + private readonly Func? canExecute; + private readonly Action execute; - public MaterialDialogRelayCommand(Action execute, Func canExecute = null) { + public MaterialDialogRelayCommand(Action execute, Func? canExecute = null) { this.execute = execute; this.canExecute = canExecute; } - public event EventHandler CanExecuteChanged; + public event EventHandler? CanExecuteChanged; - public bool CanExecute(object parameter) { - var result = canExecute == null || canExecute(parameter); - return result; + public bool CanExecute(object? parameter) { + return canExecute == null || canExecute(parameter); } - public void Execute(object parameter) { + public void Execute(object? parameter) { execute(parameter); } @@ -32,7 +31,7 @@ public void RaiseCanExecute() { if (handler != null) { // Call CanExecute via Dispatcher.UIThread.Post to prevent CanExecute can't be called from other thread. - Dispatcher.UIThread.Post(delegate { handler?.Invoke(this, new EventArgs()); }); + Dispatcher.UIThread.Post(delegate { handler?.Invoke(this, EventArgs.Empty); }); } } } diff --git a/Material.Avalonia.Dialogs/Converters/StringToTransformConverter.cs b/Material.Avalonia.Dialogs/Converters/StringToTransformConverter.cs index 199d0ea3..d9c4c836 100644 --- a/Material.Avalonia.Dialogs/Converters/StringToTransformConverter.cs +++ b/Material.Avalonia.Dialogs/Converters/StringToTransformConverter.cs @@ -6,14 +6,14 @@ namespace Material.Dialog.Converters { public class StringToTransformConverter : IValueConverter { public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { - if (value == null) + var stringValue = value?.ToString(); + if (stringValue == null) return TransformOperation.Identity; - var r = TransformOperations.Parse(value.ToString()); - return r; + return TransformOperations.Parse(stringValue); } public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { - throw new NotImplementedException(); + throw new NotSupportedException(); } } } diff --git a/Material.Avalonia.Dialogs/CustomDialogBuilderParams.cs b/Material.Avalonia.Dialogs/CustomDialogBuilderParams.cs index 20075c4f..5ae4cf5f 100644 --- a/Material.Avalonia.Dialogs/CustomDialogBuilderParams.cs +++ b/Material.Avalonia.Dialogs/CustomDialogBuilderParams.cs @@ -5,7 +5,7 @@ namespace Material.Dialog { public class CustomDialogBuilderParams : DialogWindowBuilderParamsBase { - public object Content = null; - public IDataTemplate ContentTemplate = null; + public object? Content = null; + public IDataTemplate? ContentTemplate = null; } } \ No newline at end of file diff --git a/Material.Avalonia.Dialogs/DateTimePickerDialogResult.cs b/Material.Avalonia.Dialogs/DateTimePickerDialogResult.cs index 2441b778..12a01cc1 100644 --- a/Material.Avalonia.Dialogs/DateTimePickerDialogResult.cs +++ b/Material.Avalonia.Dialogs/DateTimePickerDialogResult.cs @@ -8,19 +8,19 @@ public class DateTimePickerDialogResult : IDialogResult { // ReSharper disable once InconsistentNaming internal TimeSpan _timeSpan; - internal string Result; + internal string? _result; public DateTimePickerDialogResult() { } public DateTimePickerDialogResult(string result, TimeSpan time) { - Result = result; + _result = result; _timeSpan = time; } public DateTimePickerDialogResult(string result, DateTime date) { - Result = result; + _result = result; _dateTime = date; } - public string GetResult => Result; + public string? GetResult => _result; /// /// Get results of TimePicker. diff --git a/Material.Avalonia.Dialogs/DialogResult.cs b/Material.Avalonia.Dialogs/DialogResult.cs index ec3f6114..2f66ae13 100644 --- a/Material.Avalonia.Dialogs/DialogResult.cs +++ b/Material.Avalonia.Dialogs/DialogResult.cs @@ -2,7 +2,7 @@ namespace Material.Dialog { public class DialogResult : IDialogResult { - private string result; + private string? result; public DialogResult() { } @@ -16,6 +16,6 @@ public DialogResult(string result) { /// public static DialogResult NoResult { get; private set; } = new() { result = "none" }; - public virtual string GetResult => result; + public virtual string? GetResult => result; } } \ No newline at end of file diff --git a/Material.Avalonia.Dialogs/Icons/DialogIcon.cs b/Material.Avalonia.Dialogs/Icons/DialogIcon.cs index bbf1afa1..aa3dd88b 100644 --- a/Material.Avalonia.Dialogs/Icons/DialogIcon.cs +++ b/Material.Avalonia.Dialogs/Icons/DialogIcon.cs @@ -53,18 +53,15 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e) { } private void UpdateData() { - string data = null; - DialogIconsDataFactory.DataIndex.Value?.TryGetValue(Kind, out data); - var g = StreamGeometry.Parse(data); + if (DialogIconsDataFactory.DataIndex.Value?.TryGetValue(Kind, out var data) != true) return; + var g = StreamGeometry.Parse(data!); Data = g; } private void UpdateColor() { - if (UseRecommendColor) { - string color = null; - DialogIconsDataFactory.RecommendColorIndex.Value?.TryGetValue(Kind, out color); - Foreground = SolidColorBrush.Parse(color); - } + if (!UseRecommendColor) return; + if (DialogIconsDataFactory.RecommendColorIndex.Value?.TryGetValue(Kind, out var color) != true) return; + Foreground = SolidColorBrush.Parse(color!); } } } \ No newline at end of file diff --git a/Material.Avalonia.Dialogs/Interfaces/IDialogResult.cs b/Material.Avalonia.Dialogs/Interfaces/IDialogResult.cs index 891b5073..b22cbfdd 100644 --- a/Material.Avalonia.Dialogs/Interfaces/IDialogResult.cs +++ b/Material.Avalonia.Dialogs/Interfaces/IDialogResult.cs @@ -2,6 +2,6 @@ { public interface IDialogResult { - string GetResult { get; } + string? GetResult { get; } } } \ No newline at end of file diff --git a/Material.Avalonia.Dialogs/Resources/TemplateResources.axaml.cs b/Material.Avalonia.Dialogs/Resources/TemplateResources.axaml.cs index 7a761ab1..2518c0fe 100644 --- a/Material.Avalonia.Dialogs/Resources/TemplateResources.axaml.cs +++ b/Material.Avalonia.Dialogs/Resources/TemplateResources.axaml.cs @@ -9,7 +9,7 @@ namespace Material.Dialog.Resources public class TemplateResources : ResourceDictionary { // ReSharper disable UnusedMember.Local - private void DialogButtonTemplate_OnSelectTemplateKey(object sender, SelectTemplateEventArgs e) + private void DialogButtonTemplate_OnSelectTemplateKey(object _, SelectTemplateEventArgs e) { e.TemplateKey = e.DataContext switch { diff --git a/Material.Avalonia.Dialogs/TextFieldBuilderParams.cs b/Material.Avalonia.Dialogs/TextFieldBuilderParams.cs index 8c5fc3f1..6d05b3f1 100644 --- a/Material.Avalonia.Dialogs/TextFieldBuilderParams.cs +++ b/Material.Avalonia.Dialogs/TextFieldBuilderParams.cs @@ -14,7 +14,7 @@ public class TextFieldBuilderParams { }; //[Obsolete("Currently AvaloniaUI are not supported to binding classes, do not use this before they fixed this.")] - public string Classes; + public string? Classes; public string DefaultText = ""; /// @@ -26,17 +26,17 @@ public class TextFieldBuilderParams { ///

Helper text conveys additional guidance about the input field, such as how it will be used. It should only take up a single line, being persistently visible or visible only on focus.

/// Read Material Design documentations. Text fields anatomy. Assistive elements for more information. ///
- public string HelperText = null; + public string? HelperText = null; /// /// Floating label text /// - public string Label; + public string? Label; public char MaskChar = '*'; public int MaxCountChars; - public string PlaceholderText = null; + public string? PlaceholderText = null; /// /// Define an data validate function, result using @@ -45,6 +45,6 @@ public class TextFieldBuilderParams { ///
is information about invalid field, should be string. /// ///
- public Func> Validater; + public Func>? Validater; } } \ No newline at end of file diff --git a/Material.Avalonia.Dialogs/TextFieldDialogResult.cs b/Material.Avalonia.Dialogs/TextFieldDialogResult.cs index daeffbd6..c4c61ab8 100644 --- a/Material.Avalonia.Dialogs/TextFieldDialogResult.cs +++ b/Material.Avalonia.Dialogs/TextFieldDialogResult.cs @@ -2,20 +2,21 @@ { public class TextFieldDialogResult : DialogResult { + internal TextFieldResult[] _fieldsResult; + + internal string? _result; + public TextFieldDialogResult() { } public TextFieldDialogResult(string result, TextFieldResult[] fieldsResult) { - this.result = result; - this.fieldsResult = fieldsResult; + this._result = result; + this._fieldsResult = fieldsResult; } - internal string result; - public string GetResult => result; - - internal TextFieldResult[] fieldsResult; - public TextFieldResult[] GetFieldsResult() => fieldsResult; + public override string? GetResult => _result; + public TextFieldResult[] GetFieldsResult() => _fieldsResult; } } \ No newline at end of file diff --git a/Material.Avalonia.Dialogs/TextFieldResult.cs b/Material.Avalonia.Dialogs/TextFieldResult.cs index c41615d2..251fbdb0 100644 --- a/Material.Avalonia.Dialogs/TextFieldResult.cs +++ b/Material.Avalonia.Dialogs/TextFieldResult.cs @@ -2,6 +2,6 @@ { public class TextFieldResult { - public string Text { get; set; } + public string? Text { get; set; } } } \ No newline at end of file diff --git a/Material.Avalonia.Dialogs/ViewModels/CustomDialogViewModel.cs b/Material.Avalonia.Dialogs/ViewModels/CustomDialogViewModel.cs index 75cf6a83..872134e3 100644 --- a/Material.Avalonia.Dialogs/ViewModels/CustomDialogViewModel.cs +++ b/Material.Avalonia.Dialogs/ViewModels/CustomDialogViewModel.cs @@ -5,9 +5,9 @@ namespace Material.Dialog.ViewModels { public class CustomDialogViewModel : DialogWindowViewModel { - private object _content; + private object? _content; - public object Content + public object? Content { get => _content; set @@ -17,9 +17,9 @@ public object Content } } - private IDataTemplate _contentTemplate; + private IDataTemplate? _contentTemplate; - public IDataTemplate ContentTemplate + public IDataTemplate? ContentTemplate { get => _contentTemplate; set diff --git a/Material.Avalonia.Dialogs/ViewModels/DatePickerDialogViewModel.cs b/Material.Avalonia.Dialogs/ViewModels/DatePickerDialogViewModel.cs index 24f0fbed..14aaebdf 100644 --- a/Material.Avalonia.Dialogs/ViewModels/DatePickerDialogViewModel.cs +++ b/Material.Avalonia.Dialogs/ViewModels/DatePickerDialogViewModel.cs @@ -25,20 +25,19 @@ public DateTime DateTime } } - public DatePickerDialogViewModel(DatePickerDialog dialog) : base(dialog) - { + public DatePickerDialogViewModel(DatePickerDialog dialog) : base(dialog) { + _window = dialog; ButtonClick = new MaterialDialogRelayCommand(OnPressButton, CanPressButton); } - public bool CanPressButton(object args) + public bool CanPressButton(object? args) { return true; } - public async void OnPressButton(object args) + public async void OnPressButton(object? args) { - var button = args as DialogButton; - if (button is null) + if (args is not DialogButton button) return; await Dispatcher.UIThread.InvokeAsync(() => diff --git a/Material.Avalonia.Dialogs/ViewModels/DialogWindowViewModel.cs b/Material.Avalonia.Dialogs/ViewModels/DialogWindowViewModel.cs index 9a55c012..77d5231f 100644 --- a/Material.Avalonia.Dialogs/ViewModels/DialogWindowViewModel.cs +++ b/Material.Avalonia.Dialogs/ViewModels/DialogWindowViewModel.cs @@ -36,9 +36,9 @@ public string WindowTitle } } - private string _contentHeader; + private string? _contentHeader; - public string ContentHeader + public string? ContentHeader { get => _contentHeader; set @@ -48,9 +48,9 @@ public string ContentHeader } } - private string _contentMessage; + private string? _contentMessage; - public string ContentMessage + public string? ContentMessage { get => _contentMessage; set diff --git a/Material.Avalonia.Dialogs/ViewModels/Elements/DialogButtonViewModel.cs b/Material.Avalonia.Dialogs/ViewModels/Elements/DialogButtonViewModel.cs index f3718485..c0a873b4 100644 --- a/Material.Avalonia.Dialogs/ViewModels/Elements/DialogButtonViewModel.cs +++ b/Material.Avalonia.Dialogs/ViewModels/Elements/DialogButtonViewModel.cs @@ -46,9 +46,9 @@ public object Content } } - private ICommand _command; + private ICommand? _command; - public ICommand Command + public ICommand? Command { get => _command; set diff --git a/Material.Avalonia.Dialogs/ViewModels/Elements/ObsoleteDialogButtonViewModel.cs b/Material.Avalonia.Dialogs/ViewModels/Elements/ObsoleteDialogButtonViewModel.cs index b9063280..54182485 100644 --- a/Material.Avalonia.Dialogs/ViewModels/Elements/ObsoleteDialogButtonViewModel.cs +++ b/Material.Avalonia.Dialogs/ViewModels/Elements/ObsoleteDialogButtonViewModel.cs @@ -11,12 +11,12 @@ public ObsoleteDialogButtonViewModel(DialogWindowViewModel parent, object conten Command = new MaterialDialogRelayCommand(OnExecuteCommandHandler, CanExecuteCommandHandler); } - private bool CanExecuteCommandHandler(object arg) + private bool CanExecuteCommandHandler(object? arg) { return true; } - private void OnExecuteCommandHandler(object obj) + private void OnExecuteCommandHandler(object? obj) { if (Parent is null) return; diff --git a/Material.Avalonia.Dialogs/ViewModels/Elements/TextField/TextFieldViewModel.cs b/Material.Avalonia.Dialogs/ViewModels/Elements/TextField/TextFieldViewModel.cs index c3136ecb..7f578bbe 100644 --- a/Material.Avalonia.Dialogs/ViewModels/Elements/TextField/TextFieldViewModel.cs +++ b/Material.Avalonia.Dialogs/ViewModels/Elements/TextField/TextFieldViewModel.cs @@ -9,8 +9,8 @@ public class TextFieldViewModel : DialogViewModelBase public TextFieldDialogViewModel Parent => _parent; - public TextFieldViewModel(TextFieldDialogViewModel parent, string defaultText = default, - Func> validateHandler = null) + public TextFieldViewModel(TextFieldDialogViewModel parent, string? defaultText = default, + Func>? validateHandler = null) { _parent = parent; _text = defaultText; @@ -23,11 +23,11 @@ public TextFieldViewModel(TextFieldDialogViewModel parent, string defaultText = public event EventHandler OnValidateRequired; - public Func> ValidateHandler; + public Func>? ValidateHandler; - private string _placeholderText; + private string? _placeholderText; - public string PlaceholderText + public string? PlaceholderText { get => _placeholderText; set @@ -37,9 +37,9 @@ public string PlaceholderText } } - private string _text; + private string? _text; - public string Text + public string? Text { get => _text; set @@ -50,9 +50,9 @@ public string Text } } - private string _classes; + private string? _classes; - public string Classes + public string? Classes { get => _classes; set @@ -62,9 +62,9 @@ public string Classes } } - private string _label; + private string? _label; - public string Label + public string? Label { get => _label; set @@ -110,9 +110,9 @@ public bool IsValid } } - private string _assistiveText; + private string? _assistiveText; - public string AssistiveText + public string? AssistiveText { get => _assistiveText; set @@ -122,7 +122,7 @@ public string AssistiveText } } - private void OnTextChanged(string text) + private void OnTextChanged(string? text) { var result = DoValidate(text); @@ -135,15 +135,15 @@ private void OnTextChanged(string text) throw new DataValidationException(result.Item2); } - private Tuple DoValidate(string text) + private Tuple DoValidate(string? text) { try { - return ValidateHandler?.Invoke(text) ?? new Tuple(true, null); + return ValidateHandler?.Invoke(text) ?? new Tuple(true, null); } catch (Exception e) { - return new Tuple(false, e.Message); + return new Tuple(false, e.Message); } } } diff --git a/Material.Avalonia.Dialogs/ViewModels/TextFieldDialogViewModel.cs b/Material.Avalonia.Dialogs/ViewModels/TextFieldDialogViewModel.cs index 1a87ac46..e54ea0b3 100644 --- a/Material.Avalonia.Dialogs/ViewModels/TextFieldDialogViewModel.cs +++ b/Material.Avalonia.Dialogs/ViewModels/TextFieldDialogViewModel.cs @@ -79,14 +79,14 @@ private void Field_OnValidateRequired(object sender, bool e) public MaterialDialogRelayCommand SubmitCommand { get; } - private bool CanPressButton(object args) + private bool CanPressButton(object? args) { return ValidateFields(); } - private async void OnPressButton(object args) + private async void OnPressButton(object? args) { - if (!(args is DialogButtonViewModel button)) + if (args is not DialogButtonViewModel button) return; await Dispatcher.UIThread.InvokeAsync(() => @@ -97,7 +97,7 @@ await Dispatcher.UIThread.InvokeAsync(() => var result = new TextFieldDialogResult { - result = resultButtonId + _result = resultButtonId }; var fields = new List(); @@ -105,7 +105,7 @@ await Dispatcher.UIThread.InvokeAsync(() => foreach (var item in TextFields) fields.Add(new TextFieldResult {Text = item.Text}); - result.fieldsResult = fields.ToArray(); + result._fieldsResult = fields.ToArray(); button.Parent.DialogResult = result; Window.Close(); diff --git a/Material.Avalonia.Dialogs/ViewModels/TimePickerDialogViewModel.cs b/Material.Avalonia.Dialogs/ViewModels/TimePickerDialogViewModel.cs index a469a226..7bd58efc 100644 --- a/Material.Avalonia.Dialogs/ViewModels/TimePickerDialogViewModel.cs +++ b/Material.Avalonia.Dialogs/ViewModels/TimePickerDialogViewModel.cs @@ -136,18 +136,18 @@ public bool SecondFieldSelected } } - public TimePickerDialogViewModel(TimePickerDialog dialog) : base(dialog) - { + public TimePickerDialogViewModel(TimePickerDialog dialog) : base(dialog) { + _window = dialog; ButtonClick = new MaterialDialogRelayCommand(OnPressButton, CanPressButton); } - public bool CanPressButton(object args) + public bool CanPressButton(object? args) { return true; } - public async void OnPressButton(object args) + public async void OnPressButton(object? args) { var button = args as DialogButton; if (button is null) diff --git a/Material.Avalonia.Dialogs/ViewModels/ViewModelBase.cs b/Material.Avalonia.Dialogs/ViewModels/ViewModelBase.cs index 6f69b749..bdc2958a 100644 --- a/Material.Avalonia.Dialogs/ViewModels/ViewModelBase.cs +++ b/Material.Avalonia.Dialogs/ViewModels/ViewModelBase.cs @@ -5,9 +5,9 @@ namespace Material.Dialog.ViewModels { public class DialogViewModelBase : INotifyPropertyChanged { - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler? PropertyChanged; - protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) + protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } } \ No newline at end of file diff --git a/Material.Avalonia.Dialogs/Views/DatePickerDialog.axaml.cs b/Material.Avalonia.Dialogs/Views/DatePickerDialog.axaml.cs index b6c58bb1..03b668ac 100644 --- a/Material.Avalonia.Dialogs/Views/DatePickerDialog.axaml.cs +++ b/Material.Avalonia.Dialogs/Views/DatePickerDialog.axaml.cs @@ -19,7 +19,7 @@ public DateTimePickerDialogResult GetResult() { } public void SetNegativeResult(DialogResult result) { - Result.Result = result.GetResult; + Result._result = result.GetResult; } public void AttachViewModel(DatePickerDialogViewModel vm) { diff --git a/Material.Avalonia.Dialogs/Views/TextFieldDialog.axaml.cs b/Material.Avalonia.Dialogs/Views/TextFieldDialog.axaml.cs index fc90d0fd..4bec3931 100644 --- a/Material.Avalonia.Dialogs/Views/TextFieldDialog.axaml.cs +++ b/Material.Avalonia.Dialogs/Views/TextFieldDialog.axaml.cs @@ -30,7 +30,7 @@ public TextFieldDialogResult GetResult() { }; } - public void SetNegativeResult(DialogResult result) => Result.result = result.GetResult; + public void SetNegativeResult(DialogResult result) => Result._result = result.GetResult; private void TextFieldDialog_Closed(object sender, EventArgs e) { Opened -= TextFieldDialog_Opened; diff --git a/Material.Avalonia.Dialogs/Views/TimePickerDialog.axaml.cs b/Material.Avalonia.Dialogs/Views/TimePickerDialog.axaml.cs index 95df48e6..81bf9fc1 100644 --- a/Material.Avalonia.Dialogs/Views/TimePickerDialog.axaml.cs +++ b/Material.Avalonia.Dialogs/Views/TimePickerDialog.axaml.cs @@ -13,7 +13,7 @@ public TimePickerDialog() { public DateTimePickerDialogResult GetResult() => Result; - public void SetNegativeResult(DialogResult result) => Result.Result = result.GetResult; + public void SetNegativeResult(DialogResult result) => Result._result = result.GetResult; public void AttachViewModel(TimePickerDialogViewModel vm) { DataContext = vm; diff --git a/Material.Styles/Controls/CircleClockPicker.axaml.cs b/Material.Styles/Controls/CircleClockPicker.axaml.cs index 5f606c2c..bb7f9b6f 100644 --- a/Material.Styles/Controls/CircleClockPicker.axaml.cs +++ b/Material.Styles/Controls/CircleClockPicker.axaml.cs @@ -113,12 +113,12 @@ protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs chang if (change.Property == BoundsProperty) OnCanvasResize(change); } - private void OnCanvasResize(AvaloniaPropertyChangedEventArgs obj) { + private void OnCanvasResize(AvaloniaPropertyChangedEventArgs _) { UpdateCellPanel(); AdjustPointer(); } - private void OnNext(EventArgs a) { + private void OnNext(EventArgs _) { UpdateCellPanel(); AdjustPointer(); } diff --git a/Material.Styles/Internal/LightweightObservableBase.cs b/Material.Styles/Internal/LightweightObservableBase.cs index ba5ddab0..a4c8ca74 100644 --- a/Material.Styles/Internal/LightweightObservableBase.cs +++ b/Material.Styles/Internal/LightweightObservableBase.cs @@ -24,7 +24,7 @@ public IDisposable Subscribe(IObserver observer) { //Dispatcher.UIThread.VerifyAccess(); - var first = false; + bool first; for (;;) { if (Volatile.Read(ref _observers) == null) { diff --git a/Material.Styles/Resources/Themes/CaptionButtons.xaml b/Material.Styles/Resources/Themes/CaptionButtons.xaml index 301a26d1..91768e13 100644 --- a/Material.Styles/Resources/Themes/CaptionButtons.xaml +++ b/Material.Styles/Resources/Themes/CaptionButtons.xaml @@ -30,7 +30,7 @@ - + diff --git a/Material.Styles/Resources/Themes/MenuItem.axaml b/Material.Styles/Resources/Themes/MenuItem.axaml index a86ced1b..fdeb48c5 100644 --- a/Material.Styles/Resources/Themes/MenuItem.axaml +++ b/Material.Styles/Resources/Themes/MenuItem.axaml @@ -101,8 +101,7 @@ - + Theme="{StaticResource MaterialMenuItemStringAccessText}" /> diff --git a/Material.Styles/Resources/Themes/RefreshContainer.xaml b/Material.Styles/Resources/Themes/RefreshContainer.xaml index e244c517..00f94b1b 100644 --- a/Material.Styles/Resources/Themes/RefreshContainer.xaml +++ b/Material.Styles/Resources/Themes/RefreshContainer.xaml @@ -14,8 +14,7 @@ Content="{TemplateBinding Content}" Padding="{TemplateBinding Padding}" VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" - HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"> - + HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}" /> diff --git a/Material.Styles/Themes/Base/BaseThemeMode.cs b/Material.Styles/Themes/Base/BaseThemeMode.cs index 82e10e56..f164f381 100644 --- a/Material.Styles/Themes/Base/BaseThemeMode.cs +++ b/Material.Styles/Themes/Base/BaseThemeMode.cs @@ -18,7 +18,7 @@ internal static class BaseThemeModeExtensions { } } - public static ThemeVariant? GetVariantFromMaterialBaseThemeMode(this BaseThemeMode variant) { + public static ThemeVariant GetVariantFromMaterialBaseThemeMode(this BaseThemeMode variant) { return variant switch { BaseThemeMode.Light => Theme.MaterialLight, BaseThemeMode.Dark => Theme.MaterialDark,