diff --git a/samples/XCT.Sample/Helpers/RelayCommand.cs b/samples/XCT.Sample/Helpers/RelayCommand.cs index 453460545..ed556ddf8 100644 --- a/samples/XCT.Sample/Helpers/RelayCommand.cs +++ b/samples/XCT.Sample/Helpers/RelayCommand.cs @@ -7,25 +7,21 @@ namespace Xamarin.CommunityToolkit.Sample { public class RelayCommand : ICommand { - readonly Action execute; - readonly Func asyncExecute; + readonly Action? execute; + readonly Func? asyncExecute; + readonly Func? canExecute; - Func canExecute; int executingCount; - public RelayCommand(Action execute, Func canExecute = null) + public RelayCommand(Action execute, Func? canExecute = null) { - if (execute == null) - throw new ArgumentNullException(nameof(execute)); - this.execute = execute; + this.execute = execute ?? throw new ArgumentNullException(nameof(execute)); this.canExecute = canExecute; } - protected RelayCommand(Func execute, Func canExecute = null) // This ctor is protected here and public in a derived class, to allow simple initialization like new RelayCommand(MyMethod) without errors due to ambiguity + protected RelayCommand(Func execute, Func? canExecute = null) // This ctor is protected here and public in a derived class, to allow simple initialization like new RelayCommand(MyMethod) without errors due to ambiguity { - if (execute == null) - throw new ArgumentNullException(nameof(execute)); - asyncExecute = execute; + asyncExecute = execute ?? throw new ArgumentNullException(nameof(execute)); this.canExecute = canExecute; } @@ -34,7 +30,7 @@ public RelayCommand(Action execute, Func canExecute = null) /// /// Ignored; this is the paremeterless command class /// - public bool CanExecute(object parameter = null) + public bool CanExecute(object? parameter = null) { try { @@ -47,15 +43,12 @@ public bool CanExecute(object parameter = null) } } - public event EventHandler CanExecuteChanged; + public event EventHandler? CanExecuteChanged; - public void RaiseCanExecuteChanged() - { - CanExecuteChanged?.Invoke(this, EventArgs.Empty); - } + public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty); // Asynchronous command handling based on http://stackoverflow.com/a/31595509/6043538 - public async void Execute(object parameter = null) + public async void Execute(object? parameter = null) { var couldExecuteBeforeExecute = CanExecute(); if (!couldExecuteBeforeExecute) @@ -70,8 +63,10 @@ public async void Execute(object parameter = null) { if (execute != null) execute(); - else + else if (asyncExecute != null) await asyncExecute(); + else + throw new Exception("Execute is null"); } catch (Exception ex) { @@ -89,31 +84,30 @@ public async void Execute(object parameter = null) public class RelayCommandAsync : RelayCommand { - public RelayCommandAsync(Func execute, Func canExecute = null) - : base(execute, canExecute) { } // This ctor is public here and protected in the base class, to allow simple initialization like new RelayCommandAsync(MyMethod) without errors due to ambiguity + public RelayCommandAsync(Func execute, Func? canExecute = null) + : base(execute, canExecute) + { + // This ctor is public here and protected in the base class, to allow simple initialization like new RelayCommandAsync(MyMethod) without errors due to ambiguity + } } public class RelayCommand : ICommand { - readonly Action execute; - readonly Func asyncExecute; + readonly Action? execute; + readonly Func? asyncExecute; + readonly Func? canExecute; - Func canExecute; int executingCount; - public RelayCommand(Action execute, Func canExecute = null) + public RelayCommand(Action execute, Func? canExecute = null) { - if (execute == null) - throw new ArgumentNullException(nameof(execute)); - this.execute = execute; + this.execute = execute ?? throw new ArgumentNullException(nameof(execute)); this.canExecute = canExecute; } - protected RelayCommand(Func execute, Func canExecute = null) // This ctor is protected here and public in a derived class, to allow simple initialization like new RelayCommand(MyMethod) without errors due to ambiguity + protected RelayCommand(Func execute, Func? canExecute = null) // This ctor is protected here and public in a derived class, to allow simple initialization like new RelayCommand(MyMethod) without errors due to ambiguity { - if (execute == null) - throw new ArgumentNullException(nameof(execute)); - asyncExecute = execute; + asyncExecute = execute ?? throw new ArgumentNullException(nameof(execute)); this.canExecute = canExecute; } @@ -122,11 +116,11 @@ public RelayCommand(Action execute, Func canExecut /// /// /// - public bool CanExecute(object parameter = null) + public bool CanExecute(object? parameter = null) { try { - return canExecute != null ? canExecute((TParameter)parameter) : executingCount == 0; + return canExecute != null ? canExecute((TParameter?)parameter) : executingCount == 0; } catch (Exception ex) { @@ -135,12 +129,9 @@ public bool CanExecute(object parameter = null) } } - public event EventHandler CanExecuteChanged; + public event EventHandler? CanExecuteChanged; - public void RaiseCanExecuteChanged() - { - CanExecuteChanged?.Invoke(this, EventArgs.Empty); - } + public void RaiseCanExecuteChanged() => CanExecuteChanged?.Invoke(this, EventArgs.Empty); // Asynchronous command handling based on http://stackoverflow.com/a/31595509/6043538 public async void Execute(object parameterAsObject) @@ -159,13 +150,11 @@ public async void Execute(object parameterAsObject) var parameter = (TParameter)parameterAsObject; if (execute != null) - { execute(parameter); - } + else if (asyncExecute != null) + await asyncExecute.Invoke(parameter); else - { - await asyncExecute(parameter); - } + throw new Exception("Execute is null"); } catch (Exception ex) { @@ -183,7 +172,10 @@ public async void Execute(object parameterAsObject) public class RelayCommandAsync : RelayCommand { - public RelayCommandAsync(Func execute, Func canExecute = null) - : base(execute, canExecute) { } // This ctor is public here and protected in the base class, to allow simple initialization like new RelayCommandAsync(MyMethod) without errors due to ambiguity + public RelayCommandAsync(Func execute, Func? canExecute = null) + : base(execute, canExecute) + { + // This ctor is public here and protected in the base class, to allow simple initialization like new RelayCommandAsync(MyMethod) without errors due to ambiguity + } } } \ No newline at end of file diff --git a/samples/XCT.Sample/Helpers/XLog.cs b/samples/XCT.Sample/Helpers/XLog.cs index 88dd1c65c..79e77b027 100644 --- a/samples/XCT.Sample/Helpers/XLog.cs +++ b/samples/XCT.Sample/Helpers/XLog.cs @@ -13,7 +13,7 @@ namespace Xamarin.CommunityToolkit.Sample /// public static class XLog { - static string rootFolderPattern = null; + static string? rootFolderPattern = null; #if WINDOWS_UWP static LoggingChannel loggingChannel; #endif @@ -22,7 +22,7 @@ public static class XLog /// Call this before logging starts. /// /// Should match the top folder name(s) within the source control repository, e.g. @"\MobileRealtimePush\MobileRealtimePush\". Any folders before the first match of this pattern are omitted from the logged source file paths - public static void Init(string rootFolderPattern = null) + public static void Init(string? rootFolderPattern = null) { XLog.rootFolderPattern = rootFolderPattern; #if WINDOWS_UWP @@ -46,10 +46,10 @@ public static void Init(string rootFolderPattern = null) /// supplied by compiler, no need to specify in code unless you want to pass a deeper call context [Conditional("DEBUG")] public static void Debug( - object data = null, - string tag = null, - [CallerMemberName] string memberName = null, - [CallerFilePath] string sourceFilePath = null, + object? data = null, + string? tag = null, + [CallerMemberName] string? memberName = null, + [CallerFilePath] string? sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = -1) { var message = FormatLogString(data, tag, memberName, sourceFilePath, sourceLineNumber); @@ -75,10 +75,10 @@ public static void Debug( /// supplied by compiler, no need to specify in code unless you want to pass a deeper call context [Conditional("TRACE")] public static void Trace( - object data = null, - string tag = null, - [CallerMemberName] string memberName = null, - [CallerFilePath] string sourceFilePath = null, + object? data = null, + string? tag = null, + [CallerMemberName] string? memberName = null, + [CallerFilePath] string? sourceFilePath = null, [CallerLineNumber] int sourceLineNumber = -1) { var message = FormatLogString(data, tag, memberName, sourceFilePath, sourceLineNumber); @@ -90,9 +90,9 @@ public static void Trace( #endif } - public static string TruncateAt(this string s, int maxLength, string truncatedSuffix = "...") => s?.Length <= maxLength ? s : s.Substring(0, maxLength) + truncatedSuffix; + public static string TruncateAt(this string? s, int maxLength, string truncatedSuffix = "...") => s?.Length <= maxLength ? s : s?.Substring(0, maxLength) + truncatedSuffix; - static string FormatLogString(object data = null, string tag = null, string memberName = null, string sourceFilePath = null, int sourceLineNumber = -1) + static string FormatLogString(object? data, string? tag, string? memberName, string? sourceFilePath, int sourceLineNumber) { var line = new StringBuilder(); @@ -121,7 +121,7 @@ static string FormatLogString(object data = null, string tag = null, string memb line.Append(dataString); } - if (!string.IsNullOrEmpty(sourceFilePath)) + if (sourceFilePath != null && !string.IsNullOrEmpty(sourceFilePath)) { if (!string.IsNullOrEmpty(rootFolderPattern)) { diff --git a/samples/XCT.Sample/Pages/Converters/BoolToObjectConverterPage.xaml.cs b/samples/XCT.Sample/Pages/Converters/BoolToObjectConverterPage.xaml.cs index f2ecfdbe0..eca12a485 100644 --- a/samples/XCT.Sample/Pages/Converters/BoolToObjectConverterPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Converters/BoolToObjectConverterPage.xaml.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; - -using Xamarin.Forms; - -namespace Xamarin.CommunityToolkit.Sample.Pages.Converters +namespace Xamarin.CommunityToolkit.Sample.Pages.Converters { - public partial class BoolToObjectConverterPage + public partial class BoolToObjectConverterPage { - public BoolToObjectConverterPage() - { - InitializeComponent(); - } + public BoolToObjectConverterPage() => InitializeComponent(); } } diff --git a/samples/XCT.Sample/Pages/Converters/DoubleToIntConverterPage.xaml.cs b/samples/XCT.Sample/Pages/Converters/DoubleToIntConverterPage.xaml.cs index 01aa699eb..fd29fb21d 100644 --- a/samples/XCT.Sample/Pages/Converters/DoubleToIntConverterPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Converters/DoubleToIntConverterPage.xaml.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; - -using Xamarin.Forms; - -namespace Xamarin.CommunityToolkit.Sample.Pages.Converters +namespace Xamarin.CommunityToolkit.Sample.Pages.Converters { - public partial class DoubleToIntConverterPage + public partial class DoubleToIntConverterPage { - public DoubleToIntConverterPage() - { - InitializeComponent(); - } + public DoubleToIntConverterPage() => InitializeComponent(); } } diff --git a/samples/XCT.Sample/Pages/Converters/EnumToBoolConverterPage.xaml.cs b/samples/XCT.Sample/Pages/Converters/EnumToBoolConverterPage.xaml.cs index 65eb2fa3d..bad3953b4 100644 --- a/samples/XCT.Sample/Pages/Converters/EnumToBoolConverterPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Converters/EnumToBoolConverterPage.xaml.cs @@ -1,10 +1,7 @@ -namespace Xamarin.CommunityToolkit.Sample.Pages.Converters +namespace Xamarin.CommunityToolkit.Sample.Pages.Converters { - public partial class EnumToBoolConverterPage - { - public EnumToBoolConverterPage() - { - InitializeComponent(); - } - } + public partial class EnumToBoolConverterPage + { + public EnumToBoolConverterPage() => InitializeComponent(); + } } \ No newline at end of file diff --git a/samples/XCT.Sample/Pages/Converters/EqualConverterPage.xaml.cs b/samples/XCT.Sample/Pages/Converters/EqualConverterPage.xaml.cs index 3753f43fd..231772eea 100644 --- a/samples/XCT.Sample/Pages/Converters/EqualConverterPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Converters/EqualConverterPage.xaml.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; - -using Xamarin.Forms; - -namespace Xamarin.CommunityToolkit.Sample.Pages.Converters +namespace Xamarin.CommunityToolkit.Sample.Pages.Converters { - public partial class EqualConverterPage + public partial class EqualConverterPage { - public EqualConverterPage() - { - InitializeComponent(); - } + public EqualConverterPage() => InitializeComponent(); } } diff --git a/samples/XCT.Sample/Pages/Converters/IndexToArrayItemConverterPage.xaml.cs b/samples/XCT.Sample/Pages/Converters/IndexToArrayItemConverterPage.xaml.cs index 875cb4d9c..ba36595f5 100644 --- a/samples/XCT.Sample/Pages/Converters/IndexToArrayItemConverterPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Converters/IndexToArrayItemConverterPage.xaml.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; - -using Xamarin.Forms; - -namespace Xamarin.CommunityToolkit.Sample.Pages.Converters +namespace Xamarin.CommunityToolkit.Sample.Pages.Converters { - public partial class IndexToArrayItemConverterPage + public partial class IndexToArrayItemConverterPage { - public IndexToArrayItemConverterPage() - { - InitializeComponent(); - } + public IndexToArrayItemConverterPage() => InitializeComponent(); } } diff --git a/samples/XCT.Sample/Pages/Converters/IntToBoolConverterPage.xaml.cs b/samples/XCT.Sample/Pages/Converters/IntToBoolConverterPage.xaml.cs index 298700e29..669fe5f66 100644 --- a/samples/XCT.Sample/Pages/Converters/IntToBoolConverterPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Converters/IntToBoolConverterPage.xaml.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; - -using Xamarin.Forms; - -namespace Xamarin.CommunityToolkit.Sample.Pages.Converters +namespace Xamarin.CommunityToolkit.Sample.Pages.Converters { - public partial class IntToBoolConverterPage + public partial class IntToBoolConverterPage { - public IntToBoolConverterPage() - { - InitializeComponent(); - } + public IntToBoolConverterPage() => InitializeComponent(); } } diff --git a/samples/XCT.Sample/Pages/Converters/InvertedBoolConverterPage.xaml.cs b/samples/XCT.Sample/Pages/Converters/InvertedBoolConverterPage.xaml.cs index 0f5c5935a..9c338ea2e 100644 --- a/samples/XCT.Sample/Pages/Converters/InvertedBoolConverterPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Converters/InvertedBoolConverterPage.xaml.cs @@ -1,10 +1,7 @@ namespace Xamarin.CommunityToolkit.Sample.Pages.Converters { - public partial class InvertedBoolConverterPage + public partial class InvertedBoolConverterPage { - public InvertedBoolConverterPage() - { - InitializeComponent(); - } + public InvertedBoolConverterPage() => InitializeComponent(); } } diff --git a/samples/XCT.Sample/Pages/Converters/IsNotNullOrEmptyConverterPage.xaml.cs b/samples/XCT.Sample/Pages/Converters/IsNotNullOrEmptyConverterPage.xaml.cs index 2387d5c39..b3a0d5c36 100644 --- a/samples/XCT.Sample/Pages/Converters/IsNotNullOrEmptyConverterPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Converters/IsNotNullOrEmptyConverterPage.xaml.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; - -using Xamarin.Forms; - -namespace Xamarin.CommunityToolkit.Sample.Pages.Converters +namespace Xamarin.CommunityToolkit.Sample.Pages.Converters { - public partial class IsNotNullOrEmptyConverterPage + public partial class IsNotNullOrEmptyConverterPage { - public IsNotNullOrEmptyConverterPage() - { - InitializeComponent(); - } + public IsNotNullOrEmptyConverterPage() => InitializeComponent(); } } diff --git a/samples/XCT.Sample/Pages/Converters/ListToStringConverterPage.xaml.cs b/samples/XCT.Sample/Pages/Converters/ListToStringConverterPage.xaml.cs index 775386057..4280638e0 100644 --- a/samples/XCT.Sample/Pages/Converters/ListToStringConverterPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Converters/ListToStringConverterPage.xaml.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; - -using Xamarin.Forms; - -namespace Xamarin.CommunityToolkit.Sample.Pages.Converters +namespace Xamarin.CommunityToolkit.Sample.Pages.Converters { - public partial class ListToStringConverterPage + public partial class ListToStringConverterPage { - public ListToStringConverterPage() - { - InitializeComponent(); - } + public ListToStringConverterPage() => InitializeComponent(); } } diff --git a/samples/XCT.Sample/Pages/Converters/NotEqualConverterPage.xaml.cs b/samples/XCT.Sample/Pages/Converters/NotEqualConverterPage.xaml.cs index a2d56d681..e1d362d38 100644 --- a/samples/XCT.Sample/Pages/Converters/NotEqualConverterPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Converters/NotEqualConverterPage.xaml.cs @@ -1,15 +1,7 @@ -using System; -using System.Collections.Generic; - -using Xamarin.Forms; - -namespace Xamarin.CommunityToolkit.Sample.Pages.Converters +namespace Xamarin.CommunityToolkit.Sample.Pages.Converters { - public partial class NotEqualConverterPage + public partial class NotEqualConverterPage { - public NotEqualConverterPage() - { - InitializeComponent(); - } + public NotEqualConverterPage() => InitializeComponent(); } } diff --git a/samples/XCT.Sample/Pages/Converters/TextCaseConverterPage.xaml.cs b/samples/XCT.Sample/Pages/Converters/TextCaseConverterPage.xaml.cs index 079919177..8018c6196 100644 --- a/samples/XCT.Sample/Pages/Converters/TextCaseConverterPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Converters/TextCaseConverterPage.xaml.cs @@ -1,10 +1,7 @@ namespace Xamarin.CommunityToolkit.Sample.Pages.Converters { - public partial class TextCaseConverterPage + public partial class TextCaseConverterPage { - public TextCaseConverterPage() - { - InitializeComponent(); - } + public TextCaseConverterPage() => InitializeComponent(); } } diff --git a/samples/XCT.Sample/Pages/Effects/ShadowEffectPage.xaml.cs b/samples/XCT.Sample/Pages/Effects/ShadowEffectPage.xaml.cs index c3f683297..d8e62916b 100644 --- a/samples/XCT.Sample/Pages/Effects/ShadowEffectPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Effects/ShadowEffectPage.xaml.cs @@ -1,11 +1,7 @@ - -namespace Xamarin.CommunityToolkit.Sample.Pages.Effects +namespace Xamarin.CommunityToolkit.Sample.Pages.Effects { public partial class ShadowEffectPage { - public ShadowEffectPage() - { - InitializeComponent(); - } + public ShadowEffectPage() => InitializeComponent(); } } diff --git a/samples/XCT.Sample/Pages/Markup/SearchPage.logic.cs b/samples/XCT.Sample/Pages/Markup/SearchPage.logic.cs index 1960071c3..d7ea4e911 100644 --- a/samples/XCT.Sample/Pages/Markup/SearchPage.logic.cs +++ b/samples/XCT.Sample/Pages/Markup/SearchPage.logic.cs @@ -9,21 +9,21 @@ namespace Xamarin.CommunityToolkit.Sample public partial class SearchPage : BasePage { readonly SearchViewModel vm; - View header; + View? header; public SearchPage() { On().SetUseSafeArea(true); BackgroundColor = Color.Black; - BindingContext = new SearchViewModel(); + BindingContext = vm = new SearchViewModel(); Build(); } void Search_FocusChanged(object sender, FocusEventArgs e) { ViewExtensions.CancelAnimations(header); - header.TranslateTo(e.IsFocused ? -56 : 0, 0, 250, Easing.CubicOut); + header?.TranslateTo(e.IsFocused ? -56 : 0, 0, 250, Easing.CubicOut); } } } \ No newline at end of file diff --git a/samples/XCT.Sample/Pages/TestCases/MediaElementSourcePage.xaml.cs b/samples/XCT.Sample/Pages/TestCases/MediaElementSourcePage.xaml.cs index 39d015c1c..35799ea00 100644 --- a/samples/XCT.Sample/Pages/TestCases/MediaElementSourcePage.xaml.cs +++ b/samples/XCT.Sample/Pages/TestCases/MediaElementSourcePage.xaml.cs @@ -1,23 +1,13 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Xamarin.CommunityToolkit.Core; +using Xamarin.CommunityToolkit.Core; using Xamarin.Forms; -using Xamarin.Forms.Xaml; namespace Xamarin.CommunityToolkit.Sample.Pages.TestCases { public partial class MediaElementSourcePage { - public MediaElementSourcePage() - { - InitializeComponent(); - } + public MediaElementSourcePage() => InitializeComponent(); } - class MediaElementViewModel : BindableObject { public string VideoAsString { get; set; } = "https://tipcalculator.appwithkiss.com/video/Hint_1_2_EN_12.mov"; diff --git a/samples/XCT.Sample/Pages/TestCases/TouchEffectCollectionViewPage.xaml.cs b/samples/XCT.Sample/Pages/TestCases/TouchEffectCollectionViewPage.xaml.cs index ada32eb11..78b5f8c86 100644 --- a/samples/XCT.Sample/Pages/TestCases/TouchEffectCollectionViewPage.xaml.cs +++ b/samples/XCT.Sample/Pages/TestCases/TouchEffectCollectionViewPage.xaml.cs @@ -1,19 +1,16 @@ - -using System.Windows.Input; -using Xamarin.Forms; +using System.Windows.Input; +using Xamarin.CommunityToolkit.ObjectModel; namespace Xamarin.CommunityToolkit.Sample.Pages.TestCases { public partial class TouchEffectCollectionViewPage { - ICommand longPressCommand; - public TouchEffectCollectionViewPage() - => InitializeComponent(); - - public ICommand LongPressCommand => longPressCommand ??= new Command(() => { - this.DisplayAlert("Long Press", null, "OK"); - }); + InitializeComponent(); + LongPressCommand = new AsyncCommand(() => DisplayAlert("Long Press", null, "OK")); + } + + public ICommand LongPressCommand { get; } } } diff --git a/samples/XCT.Sample/Pages/Views/SnackBarPage.xaml.cs b/samples/XCT.Sample/Pages/Views/SnackBarPage.xaml.cs index 7a6247a4a..a0c74f101 100644 --- a/samples/XCT.Sample/Pages/Views/SnackBarPage.xaml.cs +++ b/samples/XCT.Sample/Pages/Views/SnackBarPage.xaml.cs @@ -40,6 +40,7 @@ async void DisplaySnackBarWithPadding(object sender, EventArgs args) await this.DisplaySnackBarAsync(options); } + async void DisplayToastClicked(object sender, EventArgs args) { await this.DisplayToastAsync(GenerateLongText(5)); diff --git a/samples/XCT.Sample/ViewModels/AboutViewModel.cs b/samples/XCT.Sample/ViewModels/AboutViewModel.cs index e7d242b4c..b7133e5e9 100644 --- a/samples/XCT.Sample/ViewModels/AboutViewModel.cs +++ b/samples/XCT.Sample/ViewModels/AboutViewModel.cs @@ -12,9 +12,9 @@ public class AboutViewModel : BaseViewModel { readonly GitHubClient gitHubClient = new GitHubClient(new ProductHeaderValue("XamarinCommunityToolkitSample")); - RepositoryContributor[] contributors = new RepositoryContributor[0]; + RepositoryContributor[] contributors = Array.Empty(); - RepositoryContributor selectedContributor; + RepositoryContributor? selectedContributor; string emptyViewText = "Loading data..."; @@ -37,7 +37,7 @@ public RepositoryContributor[] Contributors set => SetProperty(ref contributors, value); } - public RepositoryContributor SelectedContributor + public RepositoryContributor? SelectedContributor { get => selectedContributor; set => SetProperty(ref selectedContributor, value); diff --git a/samples/XCT.Sample/ViewModels/Base/BaseGalleryViewModel.cs b/samples/XCT.Sample/ViewModels/Base/BaseGalleryViewModel.cs index 249ebdc5c..e04cb7f92 100644 --- a/samples/XCT.Sample/ViewModels/Base/BaseGalleryViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Base/BaseGalleryViewModel.cs @@ -20,9 +20,9 @@ public BaseGalleryViewModel() public ICommand FilterCommand { get; } - public string FilterValue { private get; set; } + public string FilterValue { private get; set; } = string.Empty; - public IEnumerable FilteredItems { get; private set; } + public IEnumerable FilteredItems { get; private set; } = Array.Empty(); protected abstract IEnumerable CreateItems(); diff --git a/samples/XCT.Sample/ViewModels/Behaviors/MaxLengthReachedBehaviorViewModel.cs b/samples/XCT.Sample/ViewModels/Behaviors/MaxLengthReachedBehaviorViewModel.cs index 299e48459..af0555810 100644 --- a/samples/XCT.Sample/ViewModels/Behaviors/MaxLengthReachedBehaviorViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Behaviors/MaxLengthReachedBehaviorViewModel.cs @@ -6,7 +6,7 @@ namespace Xamarin.CommunityToolkit.Sample.ViewModels.Behaviors { public class MaxLengthReachedBehaviorViewModel : BaseViewModel { - string commandExecutions; + string commandExecutions = string.Empty; public string CommandExecutions { diff --git a/samples/XCT.Sample/ViewModels/Behaviors/ProgressBarAnimationBehaviorViewModel.cs b/samples/XCT.Sample/ViewModels/Behaviors/ProgressBarAnimationBehaviorViewModel.cs index 5e2d5680d..4e950d778 100644 --- a/samples/XCT.Sample/ViewModels/Behaviors/ProgressBarAnimationBehaviorViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Behaviors/ProgressBarAnimationBehaviorViewModel.cs @@ -1,37 +1,31 @@ -using System; -using System.Threading.Tasks; -using System.Windows.Input; -using Xamarin.CommunityToolkit.ObjectModel; +using System.Windows.Input; +using Xamarin.Forms; namespace Xamarin.CommunityToolkit.Sample.ViewModels.Behaviors { public class ProgressBarAnimationBehaviorViewModel : BaseViewModel { double progress; - ICommand setTo0Command; - ICommand setTo50Command; - ICommand setTo100Command; - public double Progress + public ProgressBarAnimationBehaviorViewModel() { - get => progress; - set - { - progress = value; - OnPropertyChanged(); - } + SetTo0Command = new Command(() => SetProgress(0)); + SetTo50Command = new Command(() => SetProgress(0.5)); + SetTo100Command = new Command(() => SetProgress(1)); } - public ICommand SetTo0Command => setTo0Command ??= new AsyncCommand(() => SetProgress(0)); + public ICommand SetTo0Command { get; } - public ICommand SetTo50Command => setTo50Command ??= new AsyncCommand(() => SetProgress(0.5)); + public ICommand SetTo50Command { get; } - public ICommand SetTo100Command => setTo100Command ??= new AsyncCommand(() => SetProgress(1)); + public ICommand SetTo100Command { get; } - async Task SetProgress(double - progress) + public double Progress { - Progress = progress; + get => progress; + set => SetProperty(ref progress, value); } + + void SetProgress(double progress) => Progress = progress; } } \ No newline at end of file diff --git a/samples/XCT.Sample/ViewModels/Behaviors/UserStoppedTypingBehaviorViewModel.cs b/samples/XCT.Sample/ViewModels/Behaviors/UserStoppedTypingBehaviorViewModel.cs index 816bc670c..8ce3761d1 100644 --- a/samples/XCT.Sample/ViewModels/Behaviors/UserStoppedTypingBehaviorViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Behaviors/UserStoppedTypingBehaviorViewModel.cs @@ -6,9 +6,7 @@ namespace Xamarin.CommunityToolkit.Sample.ViewModels.Behaviors { public class UserStoppedTypingBehaviorViewModel : BaseViewModel { - #region Properties - - string performedSearches; + string performedSearches = string.Empty; public string PerformedSearches { @@ -18,8 +16,6 @@ public string PerformedSearches public ICommand SearchCommand { get; } - #endregion Properties - public UserStoppedTypingBehaviorViewModel() => SearchCommand = CommandFactory.Create(PerformSearch); diff --git a/samples/XCT.Sample/ViewModels/Converters/ByteArrayToImageSourceViewModel.cs b/samples/XCT.Sample/ViewModels/Converters/ByteArrayToImageSourceViewModel.cs index a7e7ef2bb..44385785e 100644 --- a/samples/XCT.Sample/ViewModels/Converters/ByteArrayToImageSourceViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Converters/ByteArrayToImageSourceViewModel.cs @@ -11,9 +11,9 @@ public class ByteArrayToImageSourceViewModel : BaseViewModel { readonly GitHubClient gitHubClient = new GitHubClient(new ProductHeaderValue("XamarinCommunityToolkitSample")); - byte[] avatar; + byte[]? avatar; - public byte[] Avatar + public byte[]? Avatar { get => avatar; set => SetProperty(ref avatar, value); diff --git a/samples/XCT.Sample/ViewModels/Converters/EnumToBoolConverterViewModel.cs b/samples/XCT.Sample/ViewModels/Converters/EnumToBoolConverterViewModel.cs index 3f2a86794..872968358 100644 --- a/samples/XCT.Sample/ViewModels/Converters/EnumToBoolConverterViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Converters/EnumToBoolConverterViewModel.cs @@ -1,25 +1,25 @@ -namespace Xamarin.CommunityToolkit.Sample.ViewModels.Converters +namespace Xamarin.CommunityToolkit.Sample.ViewModels.Converters { - public class EnumToBoolConverterViewModel : BaseViewModel - { - private IssueState selectedState = IssueState.None; + public class EnumToBoolConverterViewModel : BaseViewModel + { + private IssueState selectedState = IssueState.None; - public IssueState SelectedState - { - get => selectedState; - set => SetProperty(ref selectedState, value); - } - } + public IssueState SelectedState + { + get => selectedState; + set => SetProperty(ref selectedState, value); + } + } - public enum IssueState - { - None = 0, - New = 1, - Open = 2, - Waiting = 3, - Developing = 4, - WantFix = 5, - Rejected = 6, - Resolved = 7 - } + public enum IssueState + { + None = 0, + New = 1, + Open = 2, + Waiting = 3, + Developing = 4, + WantFix = 5, + Rejected = 6, + Resolved = 7 + } } \ No newline at end of file diff --git a/samples/XCT.Sample/ViewModels/Converters/IndexToArrayItemConverterViewModel.cs b/samples/XCT.Sample/ViewModels/Converters/IndexToArrayItemConverterViewModel.cs index 115b7eecb..bca6995d3 100644 --- a/samples/XCT.Sample/ViewModels/Converters/IndexToArrayItemConverterViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Converters/IndexToArrayItemConverterViewModel.cs @@ -1,9 +1,9 @@ -using System; -namespace Xamarin.CommunityToolkit.Sample.ViewModels.Converters +namespace Xamarin.CommunityToolkit.Sample.ViewModels.Converters { public class IndexToArrayItemConverterViewModel : BaseViewModel { int index; + public int Index { get => index; diff --git a/samples/XCT.Sample/ViewModels/Converters/IsNullOrEmptyConverterViewModel.cs b/samples/XCT.Sample/ViewModels/Converters/IsNullOrEmptyConverterViewModel.cs index c2efb0616..03aa7b628 100644 --- a/samples/XCT.Sample/ViewModels/Converters/IsNullOrEmptyConverterViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Converters/IsNullOrEmptyConverterViewModel.cs @@ -7,7 +7,11 @@ namespace Xamarin.CommunityToolkit.Sample.ViewModels.Converters { public class IsNullOrEmptyConverterViewModel : BaseViewModel { - public ObservableCollection DummyItemSource { get; set; } = new ObservableCollection + string? selectedItem; + + public IsNullOrEmptyConverterViewModel() => ClearSelectionCommand = new Command(() => SelectedItem = null); + + public ObservableCollection DummyItemSource { get; } = new ObservableCollection { "Dummy Item 0", "Dummy Item 1", @@ -17,16 +21,12 @@ public class IsNullOrEmptyConverterViewModel : BaseViewModel "Dummy Item 5", }; - string selectedItem; + public ICommand ClearSelectionCommand { get; } - public string SelectedItem + public string? SelectedItem { get => selectedItem; set => SetProperty(ref selectedItem, value); } - - ICommand clearSelectionCommand; - - public ICommand ClearSelectionCommand => clearSelectionCommand ??= new Command(() => SelectedItem = null); } } diff --git a/samples/XCT.Sample/ViewModels/Converters/ItemTappedEventArgsViewModel.cs b/samples/XCT.Sample/ViewModels/Converters/ItemTappedEventArgsViewModel.cs index 8aa56632b..42500cfd7 100644 --- a/samples/XCT.Sample/ViewModels/Converters/ItemTappedEventArgsViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Converters/ItemTappedEventArgsViewModel.cs @@ -7,13 +7,12 @@ namespace Xamarin.CommunityToolkit.Sample.ViewModels.Converters { public class ItemTappedEventArgsViewModel { - public IEnumerable Items { get; } = - new List() - { - new Person() { Id = 1, Name = "Person 1" }, - new Person() { Id = 2, Name = "Person 2" }, - new Person() { Id = 3, Name = "Person 3" } - }; + public IEnumerable Items { get; } = new List() + { + new Person() { Id = 1, Name = "Person 1" }, + new Person() { Id = 2, Name = "Person 2" }, + new Person() { Id = 3, Name = "Person 3" } + }; public ICommand ItemTappedCommand { get; } = CommandFactory.Create(person => Application.Current.MainPage.DisplayAlert("Item Tapped: ", person.Name, "Cancel")); @@ -23,6 +22,6 @@ public class Person { public int Id { get; set; } - public string Name { get; set; } + public string Name { get; set; } = string.Empty; } } \ No newline at end of file diff --git a/samples/XCT.Sample/ViewModels/Converters/VariableMultiValueConverterViewModel.cs b/samples/XCT.Sample/ViewModels/Converters/VariableMultiValueConverterViewModel.cs index 6606443d2..5b1feabf6 100644 --- a/samples/XCT.Sample/ViewModels/Converters/VariableMultiValueConverterViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Converters/VariableMultiValueConverterViewModel.cs @@ -1,5 +1,4 @@ -using System; -namespace Xamarin.CommunityToolkit.Sample.ViewModels.Converters +namespace Xamarin.CommunityToolkit.Sample.ViewModels.Converters { public class VariableMultiValueConverterViewModel : BaseViewModel { diff --git a/samples/XCT.Sample/ViewModels/Effects/EffectsGalleryViewModel.cs b/samples/XCT.Sample/ViewModels/Effects/EffectsGalleryViewModel.cs index 9fadd562a..38a70cdb3 100644 --- a/samples/XCT.Sample/ViewModels/Effects/EffectsGalleryViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Effects/EffectsGalleryViewModel.cs @@ -32,20 +32,17 @@ protected override IEnumerable CreateItems() => new[] new SectionModel( typeof(TouchEffectPage), nameof(TouchEffect), - "The TouchEffect is an effect that allows changing the view's appearance depending on the touch state (normal, pressed, hovered). Also, it allows to handle long presses." - ), + "The TouchEffect is an effect that allows changing the view's appearance depending on the touch state (normal, pressed, hovered). Also, it allows to handle long presses."), new SectionModel( typeof(LifeCycleEffectPage), nameof(LifecycleEffect), - "The LifeCycle is an effect that allows you to know when a control or layout is loaded or/and unloaded in the screen and perform actions based on that." - ), - + "The LifeCycle is an effect that allows you to know when a control or layout is loaded or/and unloaded in the screen and perform actions based on that."), + new SectionModel( typeof(ShadowEffectPage), nameof(ShadowEffect), - "The ShadowEffect allows all views to display shadow."), - + "The ShadowEffect allows all views to display shadow.") }; } } \ No newline at end of file diff --git a/samples/XCT.Sample/ViewModels/Markup/SearchViewModel.cs b/samples/XCT.Sample/ViewModels/Markup/SearchViewModel.cs index 132006d9a..481dba3d4 100644 --- a/samples/XCT.Sample/ViewModels/Markup/SearchViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Markup/SearchViewModel.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Threading.Tasks; using System.Windows.Input; using Xamarin.Essentials; @@ -67,7 +68,9 @@ public SearchViewModel() public ICommand OpenHelpCommand { get; } - void Back() { } + void Back() + { + } void Like(Tweet tweet) => tweet.IsLikedByMe = !tweet.IsLikedByMe; @@ -77,18 +80,18 @@ void Back() { } public class Tweet : BaseViewModel { - public string AuthorImage { get; set; } + public string AuthorImage { get; set; } = string.Empty; - public string Header { get; set; } + public string Header { get; set; } = string.Empty; - public List Body { get; set; } + public List Body { get; set; } = Enumerable.Empty().ToList(); public bool IsLikedByMe { get; set; } } public class TextFragment { - public string Text { get; set; } + public string Text { get; set; } = string.Empty; public bool IsMatch { get; set; } } diff --git a/samples/XCT.Sample/ViewModels/SettingViewModel.cs b/samples/XCT.Sample/ViewModels/SettingViewModel.cs index 5324b25cd..ba9646adf 100644 --- a/samples/XCT.Sample/ViewModels/SettingViewModel.cs +++ b/samples/XCT.Sample/ViewModels/SettingViewModel.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Globalization; using System.Linq; using System.Windows.Input; @@ -12,26 +13,10 @@ namespace Xamarin.CommunityToolkit.Sample.ViewModels { public class SettingViewModel : BaseViewModel { - IList supportedLanguages; - - public IList SupportedLanguages - { - get => supportedLanguages; - private set => SetProperty(ref supportedLanguages, value); - } + IList supportedLanguages = Array.Empty(); Language selectedLanguage; - public Language SelectedLanguage - { - get => selectedLanguage; - set => SetProperty(ref selectedLanguage, value); - } - - public LocalizedString AppVersion { get; } = new LocalizedString(() => string.Format(AppResources.Version, AppInfo.VersionString)); - - public ICommand ChangeLanguageCommand { get; } - public SettingViewModel() { LoadLanguages(); @@ -43,6 +28,22 @@ public SettingViewModel() }); } + public LocalizedString AppVersion { get; } = new LocalizedString(() => string.Format(AppResources.Version, AppInfo.VersionString)); + + public ICommand ChangeLanguageCommand { get; } + + public Language SelectedLanguage + { + get => selectedLanguage; + set => SetProperty(ref selectedLanguage, value); + } + + public IList SupportedLanguages + { + get => supportedLanguages; + private set => SetProperty(ref supportedLanguages, value); + } + void LoadLanguages() { SupportedLanguages = new List() diff --git a/samples/XCT.Sample/ViewModels/Views/ExpanderViewModel.cs b/samples/XCT.Sample/ViewModels/Views/ExpanderViewModel.cs index 108859756..9281f689f 100644 --- a/samples/XCT.Sample/ViewModels/Views/ExpanderViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Views/ExpanderViewModel.cs @@ -46,7 +46,7 @@ public ExpanderViewModel() public sealed class Item : BaseViewModel { - string name; + string name = string.Empty; bool isExpanded; bool isEnabled = true; diff --git a/samples/XCT.Sample/ViewModels/Views/PopupControlViewModel.cs b/samples/XCT.Sample/ViewModels/Views/PopupControlViewModel.cs index 2e6fd0d7d..85e924594 100644 --- a/samples/XCT.Sample/ViewModels/Views/PopupControlViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Views/PopupControlViewModel.cs @@ -13,7 +13,8 @@ public class PopupGalleryViewModel { INavigation Navigation => App.Current.MainPage.Navigation; - public IEnumerable Examples { get; } = new List { + public IEnumerable Examples { get; } = new[] + { new SectionModel(typeof(SimplePopup), "Simple Popup", Color.Red, "Displays a basic popup centered on the screen"), new SectionModel(typeof(PopupPositionPage), "Custom Positioning Popup", Color.Red, "Displays a basic popup anywhere on the screen using VerticalOptions and HorizontalOptions"), new SectionModel(typeof(ButtonPopup), "Popup With 1 Button", Color.Red, "Displays a basic popup with a confirm button"), @@ -37,7 +38,7 @@ async void OnDisplayPopup(Type popupType) if (view is Popup popup) { var result = await Navigation.ShowPopupAsync(popup); - await App.Current.MainPage.DisplayAlert("Popup Result", result, "OKAY"); + await Application.Current.MainPage.DisplayAlert("Popup Result", result, "OKAY"); } else if (view is BasePopup basePopup) { diff --git a/samples/XCT.Sample/ViewModels/Views/StateLayoutViewModel.cs b/samples/XCT.Sample/ViewModels/Views/StateLayoutViewModel.cs index d1d63e27c..f856df57d 100644 --- a/samples/XCT.Sample/ViewModels/Views/StateLayoutViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Views/StateLayoutViewModel.cs @@ -7,7 +7,7 @@ namespace Xamarin.CommunityToolkit.Sample.ViewModels.Views { public class StateLayoutViewModel : BaseViewModel { - string customState; + string customState = string.Empty; LayoutState currentState; LayoutState mainState; diff --git a/samples/XCT.Sample/ViewModels/Views/TabItemsSourceViewModel.cs b/samples/XCT.Sample/ViewModels/Views/TabItemsSourceViewModel.cs index 451391518..4d890f101 100644 --- a/samples/XCT.Sample/ViewModels/Views/TabItemsSourceViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Views/TabItemsSourceViewModel.cs @@ -7,11 +7,16 @@ namespace Xamarin.CommunityToolkit.Sample.ViewModels.Views { public class Monkey { - public string Index { get; set; } - public string Name { get; set; } - public string Location { get; set; } - public string Details { get; set; } - public string Image { get; set; } + public string Index { get; set; } = string.Empty; + + public string Name { get; set; } = string.Empty; + + public string Location { get; set; } = string.Empty; + + public string Details { get; set; } = string.Empty; + + public string Image { get; set; } = string.Empty; + public Color Color { get; set; } } @@ -25,112 +30,106 @@ public TabItemsSourceViewModel() UpdateDataCommand = CommandFactory.Create(UpdateData); } - public ObservableCollection Monkeys { get; set; } + public ObservableCollection Monkeys { get; } = LoadMonkeys(); public ICommand ClearDataCommand { get; } public ICommand UpdateDataCommand { get; } - void LoadMonkeys() + static ObservableCollection LoadMonkeys() => new ObservableCollection { - Monkeys = new ObservableCollection + new Monkey { - new Monkey - { - Index = "0", - Name = "Baboon", - Location = "Africa & Asia", - Details = "Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae.", - Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg", - Color = Color.LightSalmon - }, - - new Monkey - { - Index = "1", - Name = "Capuchin Monkey", - Location = "Central & South America", - Details = "The capuchin monkeys are New World monkeys of the subfamily Cebinae. Prior to 2011, the subfamily contained only a single genus, Cebus.", - Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Capuchin_Costa_Rica.jpg/200px-Capuchin_Costa_Rica.jpg", - Color = Color.LightBlue - }, - - new Monkey - { - Index = "2", - Name = "Blue Monkey", - Location = "Central and East Africa", - Details = "The blue monkey or diademed monkey is a species of Old World monkey native to Central and East Africa, ranging from the upper Congo River basin east to the East African Rift and south to northern Angola and Zambia", - Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/83/BlueMonkey.jpg/220px-BlueMonkey.jpg", - Color = Color.LightSlateGray - }, - - new Monkey - { - Index = "3", - Name = "Squirrel Monkey", - Location = "Central & South America", - Details = "The squirrel monkeys are the New World monkeys of the genus Saimiri. They are the only genus in the subfamily Saimirinae. The name of the genus Saimiri is of Tupi origin, and was also used as an English name by early researchers.", - Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Saimiri_sciureus-1_Luc_Viatour.jpg/220px-Saimiri_sciureus-1_Luc_Viatour.jpg", - Color = Color.Chocolate - }, - - new Monkey - { - Index = "4", - Name = "Golden Lion Tamarin", - Location = "Brazil", - Details = "The golden lion tamarin also known as the golden marmoset, is a small New World monkey of the family Callitrichidae.", - Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/87/Golden_lion_tamarin_portrait3.jpg/220px-Golden_lion_tamarin_portrait3.jpg", - Color = Color.Violet - }, - - new Monkey - { - Index = "5", - Name = "Howler Monkey", - Location = "South America", - Details = "Howler monkeys are among the largest of the New World monkeys. Fifteen species are currently recognised. Previously classified in the family Cebidae, they are now placed in the family Atelidae.", - Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Alouatta_guariba.jpg/200px-Alouatta_guariba.jpg", - Color = Color.Aqua - }, - - new Monkey - { - Index = "6", - Name = "Japanese Macaque", - Location = "Japan", - Details = "The Japanese macaque, is a terrestrial Old World monkey species native to Japan. They are also sometimes known as the snow monkey because they live in areas where snow covers the ground for months each", - Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Macaca_fuscata_fuscata1.jpg/220px-Macaca_fuscata_fuscata1.jpg", - Color = Color.OrangeRed - }, - - new Monkey - { - Index = "7", - Name = "Mandrill", - Location = "Southern Cameroon, Gabon, Equatorial Guinea, and Congo", - Details = "The mandrill is a primate of the Old World monkey family, closely related to the baboons and even more closely to the drill. It is found in southern Cameroon, Gabon, Equatorial Guinea, and Congo.", - Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/7/75/Mandrill_at_san_francisco_zoo.jpg/220px-Mandrill_at_san_francisco_zoo.jpg", - Color = Color.MediumPurple - }, - - new Monkey - { - Index = "8", - Name = "Proboscis Monkey", - Location = "Borneo", - Details = "The proboscis monkey or long-nosed monkey, known as the bekantan in Malay, is a reddish-brown arboreal Old World monkey that is endemic to the south-east Asian island of Borneo.", - Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/Proboscis_Monkey_in_Borneo.jpg/250px-Proboscis_Monkey_in_Borneo.jpg", - Color = Color.Pink - } - }; - } + Index = "0", + Name = "Baboon", + Location = "Africa & Asia", + Details = "Baboons are African and Arabian Old World monkeys belonging to the genus Papio, part of the subfamily Cercopithecinae.", + Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/f/fc/Papio_anubis_%28Serengeti%2C_2009%29.jpg/200px-Papio_anubis_%28Serengeti%2C_2009%29.jpg", + Color = Color.LightSalmon + }, + + new Monkey + { + Index = "1", + Name = "Capuchin Monkey", + Location = "Central & South America", + Details = "The capuchin monkeys are New World monkeys of the subfamily Cebinae. Prior to 2011, the subfamily contained only a single genus, Cebus.", + Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/4/40/Capuchin_Costa_Rica.jpg/200px-Capuchin_Costa_Rica.jpg", + Color = Color.LightBlue + }, + + new Monkey + { + Index = "2", + Name = "Blue Monkey", + Location = "Central and East Africa", + Details = "The blue monkey or diademed monkey is a species of Old World monkey native to Central and East Africa, ranging from the upper Congo River basin east to the East African Rift and south to northern Angola and Zambia", + Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/83/BlueMonkey.jpg/220px-BlueMonkey.jpg", + Color = Color.LightSlateGray + }, + + new Monkey + { + Index = "3", + Name = "Squirrel Monkey", + Location = "Central & South America", + Details = "The squirrel monkeys are the New World monkeys of the genus Saimiri. They are the only genus in the subfamily Saimirinae. The name of the genus Saimiri is of Tupi origin, and was also used as an English name by early researchers.", + Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/2/20/Saimiri_sciureus-1_Luc_Viatour.jpg/220px-Saimiri_sciureus-1_Luc_Viatour.jpg", + Color = Color.Chocolate + }, + + new Monkey + { + Index = "4", + Name = "Golden Lion Tamarin", + Location = "Brazil", + Details = "The golden lion tamarin also known as the golden marmoset, is a small New World monkey of the family Callitrichidae.", + Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/8/87/Golden_lion_tamarin_portrait3.jpg/220px-Golden_lion_tamarin_portrait3.jpg", + Color = Color.Violet + }, + + new Monkey + { + Index = "5", + Name = "Howler Monkey", + Location = "South America", + Details = "Howler monkeys are among the largest of the New World monkeys. Fifteen species are currently recognised. Previously classified in the family Cebidae, they are now placed in the family Atelidae.", + Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/0/0d/Alouatta_guariba.jpg/200px-Alouatta_guariba.jpg", + Color = Color.Aqua + }, - void ClearData() - { - Monkeys.Clear(); - } + new Monkey + { + Index = "6", + Name = "Japanese Macaque", + Location = "Japan", + Details = "The Japanese macaque, is a terrestrial Old World monkey species native to Japan. They are also sometimes known as the snow monkey because they live in areas where snow covers the ground for months each", + Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/c/c1/Macaca_fuscata_fuscata1.jpg/220px-Macaca_fuscata_fuscata1.jpg", + Color = Color.OrangeRed + }, + + new Monkey + { + Index = "7", + Name = "Mandrill", + Location = "Southern Cameroon, Gabon, Equatorial Guinea, and Congo", + Details = "The mandrill is a primate of the Old World monkey family, closely related to the baboons and even more closely to the drill. It is found in southern Cameroon, Gabon, Equatorial Guinea, and Congo.", + Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/7/75/Mandrill_at_san_francisco_zoo.jpg/220px-Mandrill_at_san_francisco_zoo.jpg", + Color = Color.MediumPurple + }, + + new Monkey + { + Index = "8", + Name = "Proboscis Monkey", + Location = "Borneo", + Details = "The proboscis monkey or long-nosed monkey, known as the bekantan in Malay, is a reddish-brown arboreal Old World monkey that is endemic to the south-east Asian island of Borneo.", + Image = "http://upload.wikimedia.org/wikipedia/commons/thumb/e/e5/Proboscis_Monkey_in_Borneo.jpg/250px-Proboscis_Monkey_in_Borneo.jpg", + Color = Color.Pink + } + }; + + void ClearData() => Monkeys.Clear(); void UpdateData() { diff --git a/samples/XCT.Sample/ViewModels/Views/Tabs/LazyTestViewModel.cs b/samples/XCT.Sample/ViewModels/Views/Tabs/LazyTestViewModel.cs index bb1934888..e3f6c5828 100644 --- a/samples/XCT.Sample/ViewModels/Views/Tabs/LazyTestViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Views/Tabs/LazyTestViewModel.cs @@ -6,7 +6,7 @@ sealed class LazyTestViewModel : ObservableObject { public static LazyTestViewModel Current { get; } = new LazyTestViewModel(); - string title; + string title = string.Empty; public string Title { diff --git a/samples/XCT.Sample/ViewModels/Views/Tabs/NormalTestViewModel.cs b/samples/XCT.Sample/ViewModels/Views/Tabs/NormalTestViewModel.cs index ff764bcf8..81c51d12d 100644 --- a/samples/XCT.Sample/ViewModels/Views/Tabs/NormalTestViewModel.cs +++ b/samples/XCT.Sample/ViewModels/Views/Tabs/NormalTestViewModel.cs @@ -6,7 +6,7 @@ sealed class NormalTestViewModel : ObservableObject { public static NormalTestViewModel Current { get; } = new NormalTestViewModel(); - string loadedViews; + string loadedViews = string.Empty; public string LoadedViews { diff --git a/samples/XCT.Sample/Xamarin.CommunityToolkit.Sample.csproj b/samples/XCT.Sample/Xamarin.CommunityToolkit.Sample.csproj index 6c19fb7d5..dc869bed2 100644 --- a/samples/XCT.Sample/Xamarin.CommunityToolkit.Sample.csproj +++ b/samples/XCT.Sample/Xamarin.CommunityToolkit.Sample.csproj @@ -3,6 +3,9 @@ netstandard2.0 true + enable + nullable + latest @@ -11,6 +14,7 @@ +