Pārlūkot izejas kodu

fix: Null Annotation

Giuseppe Lippolis 3 gadi atpakaļ
vecāks
revīzija
92291b7d9a
1 mainītis faili ar 19 papildinājumiem un 17 dzēšanām
  1. 19 17
      samples/IntegrationTestApp/MainWindow.axaml.cs

+ 19 - 17
samples/IntegrationTestApp/MainWindow.axaml.cs

@@ -1,4 +1,3 @@
-using System;
 using System.Collections.Generic;
 using System.Linq;
 using Avalonia;
@@ -31,20 +30,23 @@ namespace IntegrationTestApp
 
         private void InitializeViewMenu()
         {
-            var mainTabs = this.FindControl<TabControl>("MainTabs");
+            var mainTabs = this.Get<TabControl>("MainTabs");
             var viewMenu = (NativeMenuItem)NativeMenu.GetMenu(this).Items[1];
 
-            foreach (TabItem tabItem in mainTabs.Items)
+            if (mainTabs.Items is not null)
             {
-                var menuItem = new NativeMenuItem
+                foreach (TabItem tabItem in mainTabs.Items)
                 {
-                    Header = (string)tabItem.Header!,
-                    IsChecked = tabItem.IsSelected,
-                    ToggleType = NativeMenuItemToggleType.Radio,
-                };
-
-                menuItem.Click += (s, e) => tabItem.IsSelected = true;
-                viewMenu.Menu.Items.Add(menuItem);
+                    var menuItem = new NativeMenuItem
+                    {
+                        Header = (string)tabItem.Header!,
+                        IsChecked = tabItem.IsSelected,
+                        ToggleType = NativeMenuItemToggleType.Radio,
+                    };
+
+                    menuItem.Click += (s, e) => tabItem.IsSelected = true;
+                    viewMenu?.Menu?.Items.Add(menuItem);
+                }
             }
         }
 
@@ -107,8 +109,8 @@ namespace IntegrationTestApp
 
         private void MenuClicked(object? sender, RoutedEventArgs e)
         {
-            var clickedMenuItemTextBlock = this.FindControl<TextBlock>("ClickedMenuItem");
-            clickedMenuItemTextBlock.Text = ((MenuItem)sender!).Header.ToString();
+            var clickedMenuItemTextBlock = this.Get<TextBlock>("ClickedMenuItem");
+            clickedMenuItemTextBlock.Text = (sender as MenuItem)?.Header?.ToString();
         }
 
         private void OnButtonClick(object? sender, RoutedEventArgs e)
@@ -116,13 +118,13 @@ namespace IntegrationTestApp
             var source = e.Source as Button;
 
             if (source?.Name == "ComboBoxSelectionClear")
-                this.FindControl<ComboBox>("BasicComboBox").SelectedIndex = -1;
+                this.Get<ComboBox>("BasicComboBox").SelectedIndex = -1;
             if (source?.Name == "ComboBoxSelectFirst")
-                this.FindControl<ComboBox>("BasicComboBox").SelectedIndex = 0;
+                this.Get<ComboBox>("BasicComboBox").SelectedIndex = 0;
             if (source?.Name == "ListBoxSelectionClear")
-                this.FindControl<ListBox>("BasicListBox").SelectedIndex = -1;
+                this.Get<ListBox>("BasicListBox").SelectedIndex = -1;
             if (source?.Name == "MenuClickedMenuItemReset")
-                this.FindControl<TextBlock>("ClickedMenuItem").Text = "None";
+                this.Get<TextBlock>("ClickedMenuItem").Text = "None";
             if (source?.Name == "ShowWindow")
                 ShowWindow();
             if (source?.Name == "SendToBack")