From 2bf853aca940d99fc9544223a0f2f4430d629291 Mon Sep 17 00:00:00 2001 From: Giuseppe Lippolis Date: Sat, 4 Jun 2022 11:57:58 +0200 Subject: [PATCH] fix some null annotation in ControlCatalog --- .../Converter/MathSubtractConverter.cs | 10 ++++-- .../ControlCatalog/DecoratedWindow.xaml.cs | 10 +++--- samples/ControlCatalog/MainView.xaml.cs | 16 ++++----- samples/ControlCatalog/MainWindow.xaml.cs | 6 ++-- samples/ControlCatalog/Models/Countries.cs | 4 +-- .../Models/GDPValueConverter.cs | 4 +-- samples/ControlCatalog/Models/Person.cs | 16 ++++----- .../Pages/AutoCompleteBoxPage.xaml.cs | 33 +++++++++++-------- .../Pages/ButtonSpinnerPage.xaml.cs | 2 +- .../ControlCatalog/Pages/ButtonsPage.xaml.cs | 4 +-- .../Pages/CalendarDatePickerPage.xaml.cs | 12 +++---- .../ControlCatalog/Pages/CalendarPage.xaml.cs | 4 +-- .../ControlCatalog/Pages/CarouselPage.xaml.cs | 11 ++++--- .../Pages/ContextFlyoutPage.xaml.cs | 22 ++++++------- .../Pages/ContextMenuPage.xaml.cs | 6 ++-- .../ControlCatalog/Pages/DataGridPage.xaml.cs | 8 ++--- .../Pages/DateTimePickerPage.xaml.cs | 4 +-- .../ControlCatalog/Pages/DialogsPage.xaml.cs | 32 +++++++++--------- .../Pages/DragAndDropPage.xaml.cs | 6 ++-- .../ControlCatalog/Pages/FlyoutsPage.axaml.cs | 8 ++--- .../ControlCatalog/Pages/ImagePage.xaml.cs | 13 +++++--- .../Pages/ItemsRepeaterPage.xaml.cs | 26 ++++++++------- .../ControlCatalog/Pages/LabelsPage.axaml.cs | 2 +- samples/ControlCatalog/Pages/MenuPage.xaml.cs | 2 +- .../Pages/NativeEmbedPage.xaml.cs | 2 ++ .../Pages/NumericUpDownPage.xaml.cs | 10 +++--- samples/ControlCatalog/Pages/ScreenPage.cs | 2 +- .../Pages/TabControlPage.xaml.cs | 12 +++---- .../ControlCatalog/Pages/TabStripPage.xaml.cs | 2 +- .../ViewModels/ApplicationViewModel.cs | 2 +- .../ViewModels/ContextPageViewModel.cs | 2 +- .../ViewModels/CursorPageViewModel.cs | 2 +- .../ViewModels/ItemsRepeaterPageViewModel.cs | 19 ++++++----- .../ViewModels/MainWindowViewModel.cs | 13 ++++---- .../ViewModels/MenuItemViewModel.cs | 8 ++--- .../ViewModels/MenuPageViewModel.cs | 2 +- .../ViewModels/NotificationViewModel.cs | 4 +-- ...ransitioningContentControlPageViewModel.cs | 14 ++++---- .../ViewModels/TreeViewPageViewModel.cs | 4 +-- 39 files changed, 190 insertions(+), 169 deletions(-) diff --git a/samples/ControlCatalog/Converter/MathSubtractConverter.cs b/samples/ControlCatalog/Converter/MathSubtractConverter.cs index 009a56c0ec..6f3c99abe8 100644 --- a/samples/ControlCatalog/Converter/MathSubtractConverter.cs +++ b/samples/ControlCatalog/Converter/MathSubtractConverter.cs @@ -6,12 +6,16 @@ namespace ControlCatalog.Converter; public class MathSubtractConverter : IValueConverter { - public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture) { - return (double)value - (double)parameter; + if (value is double dv && parameter is double dp) + { + return dv - dp; + } + return double.NaN; } - public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture) { throw new NotSupportedException(); } diff --git a/samples/ControlCatalog/DecoratedWindow.xaml.cs b/samples/ControlCatalog/DecoratedWindow.xaml.cs index a1383b9107..ed30b7f491 100644 --- a/samples/ControlCatalog/DecoratedWindow.xaml.cs +++ b/samples/ControlCatalog/DecoratedWindow.xaml.cs @@ -15,7 +15,7 @@ namespace ControlCatalog void SetupSide(string name, StandardCursorType cursor, WindowEdge edge) { - var ctl = this.FindControl(name); + var ctl = this.Get(name); ctl.Cursor = new Cursor(cursor); ctl.PointerPressed += (i, e) => { @@ -26,7 +26,7 @@ namespace ControlCatalog private void InitializeComponent() { AvaloniaXamlLoader.Load(this); - this.FindControl("TitleBar").PointerPressed += (i, e) => + this.Get("TitleBar").PointerPressed += (i, e) => { PlatformImpl?.BeginMoveDrag(e); }; @@ -38,12 +38,12 @@ namespace ControlCatalog SetupSide("TopRight", StandardCursorType.TopRightCorner, WindowEdge.NorthEast); SetupSide("BottomLeft", StandardCursorType.BottomLeftCorner, WindowEdge.SouthWest); SetupSide("BottomRight", StandardCursorType.BottomRightCorner, WindowEdge.SouthEast); - this.FindControl"; - var mfxt = this.FindControl("MenuFlyoutXamlText"); + var mfxt = this.Get("MenuFlyoutXamlText"); mfxt.Text = ""; - var afxt = this.FindControl("AttachedFlyoutXamlText"); + var afxt = this.Get("AttachedFlyoutXamlText"); afxt.Text = "\n" + " \n" + " \n" + @@ -66,7 +66,7 @@ namespace ControlCatalog.Pages "\n\n In DoubleTapped handler:\n" + "FlyoutBase.ShowAttachedFlyout(AttachedFlyoutPanel);"; - var sfxt = this.FindControl("SharedFlyoutXamlText"); + var sfxt = this.Get("SharedFlyoutXamlText"); sfxt.Text = "Declare a flyout in Resources:\n" + "\n" + " \n" + diff --git a/samples/ControlCatalog/Pages/ImagePage.xaml.cs b/samples/ControlCatalog/Pages/ImagePage.xaml.cs index d8f4d6d5a2..45043aa5af 100644 --- a/samples/ControlCatalog/Pages/ImagePage.xaml.cs +++ b/samples/ControlCatalog/Pages/ImagePage.xaml.cs @@ -17,9 +17,9 @@ namespace ControlCatalog.Pages public ImagePage() { InitializeComponent(); - _bitmapImage = this.FindControl("bitmapImage"); - _drawingImage = this.FindControl("drawingImage"); - _croppedImage = this.FindControl("croppedImage"); + _bitmapImage = this.Get("bitmapImage"); + _drawingImage = this.Get("drawingImage"); + _croppedImage = this.Get("croppedImage"); } private void InitializeComponent() @@ -50,8 +50,11 @@ namespace ControlCatalog.Pages if (_croppedImage != null) { var comboxBox = (ComboBox)sender; - var croppedBitmap = _croppedImage.Source as CroppedBitmap; - croppedBitmap.SourceRect = GetCropRect(comboxBox.SelectedIndex); + if (_croppedImage.Source is CroppedBitmap croppedBitmap) + { + croppedBitmap.SourceRect = GetCropRect(comboxBox.SelectedIndex); + } + } } diff --git a/samples/ControlCatalog/Pages/ItemsRepeaterPage.xaml.cs b/samples/ControlCatalog/Pages/ItemsRepeaterPage.xaml.cs index c329061fe3..70c7b1acb0 100644 --- a/samples/ControlCatalog/Pages/ItemsRepeaterPage.xaml.cs +++ b/samples/ControlCatalog/Pages/ItemsRepeaterPage.xaml.cs @@ -24,11 +24,11 @@ namespace ControlCatalog.Pages public ItemsRepeaterPage() { this.InitializeComponent(); - _repeater = this.FindControl("repeater"); - _scroller = this.FindControl("scroller"); - _scrollToLast = this.FindControl