diff --git a/.github/PULL_REQUEST_TEMPLATE.md b/.github/PULL_REQUEST_TEMPLATE.md index 46e8665945..2f63750cdc 100644 --- a/.github/PULL_REQUEST_TEMPLATE.md +++ b/.github/PULL_REQUEST_TEMPLATE.md @@ -21,7 +21,7 @@ - [ ] Consider submitting a PR to https://github.com/AvaloniaUI/Documentation with user documentation ## Breaking changes - + ## Obsoletions / Deprecations diff --git a/build/HarfBuzzSharp.props b/build/HarfBuzzSharp.props index 85e7a1f34d..620ec58ff3 100644 --- a/build/HarfBuzzSharp.props +++ b/build/HarfBuzzSharp.props @@ -1,7 +1,7 @@  - - - + + + diff --git a/build/ReactiveUI.props b/build/ReactiveUI.props index c3b136d41d..1911c02677 100644 --- a/build/ReactiveUI.props +++ b/build/ReactiveUI.props @@ -1,5 +1,5 @@ - + diff --git a/build/SkiaSharp.props b/build/SkiaSharp.props index d54cffba08..cc573825cd 100644 --- a/build/SkiaSharp.props +++ b/build/SkiaSharp.props @@ -1,7 +1,7 @@  - - - + + + diff --git a/samples/ControlCatalog/DecoratedWindow.xaml b/samples/ControlCatalog/DecoratedWindow.xaml index 5251a2fa55..c778b31c42 100644 --- a/samples/ControlCatalog/DecoratedWindow.xaml +++ b/samples/ControlCatalog/DecoratedWindow.xaml @@ -2,7 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="ControlCatalog.DecoratedWindow" Title="Avalonia Control Gallery" - xmlns:local="clr-namespace:ControlCatalog" HasSystemDecorations="False" Name="Window"> + xmlns:local="clr-namespace:ControlCatalog" SystemDecorations="None" Name="Window"> diff --git a/samples/ControlCatalog/MainView.xaml.cs b/samples/ControlCatalog/MainView.xaml.cs index 58433f13ce..7133ddaa6a 100644 --- a/samples/ControlCatalog/MainView.xaml.cs +++ b/samples/ControlCatalog/MainView.xaml.cs @@ -22,8 +22,8 @@ namespace ControlCatalog if (AvaloniaLocator.Current?.GetService()?.GetRuntimeInfo().IsDesktop == true) { - IList tabItems = ((IList)sideBar.Items); - tabItems.Add(new TabItem() + var tabItems = (sideBar.Items as IList); + tabItems?.Add(new TabItem() { Header = "Screens", Content = new ScreenPage() @@ -36,7 +36,7 @@ namespace ControlCatalog { if (themes.SelectedItem is CatalogTheme theme) { - var themeStyle = Application.Current.Styles[0]; + var themeStyle = Application.Current!.Styles[0]; if (theme == CatalogTheme.FluentLight) { if (App.Fluent.Mode != FluentThemeMode.Light) diff --git a/samples/ControlCatalog/MainWindow.xaml b/samples/ControlCatalog/MainWindow.xaml index 1e4bf2de38..d5513904c0 100644 --- a/samples/ControlCatalog/MainWindow.xaml +++ b/samples/ControlCatalog/MainWindow.xaml @@ -18,15 +18,15 @@ - - + + + Click="OnCloseClicked" /> diff --git a/samples/ControlCatalog/Models/Person.cs b/samples/ControlCatalog/Models/Person.cs index 2dfa02c7ed..99bc50250b 100644 --- a/samples/ControlCatalog/Models/Person.cs +++ b/samples/ControlCatalog/Models/Person.cs @@ -85,7 +85,7 @@ namespace ControlCatalog.Models } else { - if (_errorLookup.TryGetValue(propertyName, out List errorList)) + if (_errorLookup.TryGetValue(propertyName, out var errorList)) { errorList.Clear(); errorList.Add(error!); @@ -114,12 +114,12 @@ namespace ControlCatalog.Models PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } - public IEnumerable? GetErrors(string propertyName) + public IEnumerable GetErrors(string? propertyName) { - if (_errorLookup.TryGetValue(propertyName, out List errorList)) + if (propertyName is { } && _errorLookup.TryGetValue(propertyName, out var errorList)) return errorList; else - return null; + return Array.Empty(); } } } diff --git a/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml b/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml index 46f3705ffd..faa12bc8da 100644 --- a/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml +++ b/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml @@ -28,7 +28,7 @@ - + diff --git a/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml.cs b/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml.cs index 7a0957b02d..bc18327f12 100644 --- a/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml.cs +++ b/samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml.cs @@ -1,8 +1,6 @@ using Avalonia.Controls; using Avalonia.LogicalTree; -using Avalonia.Markup; using Avalonia.Markup.Xaml; -using Avalonia.Markup.Data; using System; using System.Collections.Generic; using System.Linq; @@ -161,23 +159,23 @@ namespace ControlCatalog.Pages private bool LastWordContains(string? searchText, string? item) { var words = searchText?.Split(' ') ?? Array.Empty(); - var options = Sentences.Select(x => x.First).ToArray(); + var options = Sentences.Select(x => x.First) + .ToArray?>(); for (var i = 0; i < words.Length; ++i) { var word = words[i]; for (var j = 0; word is { } && j < options.Length; ++j) { - var option = options[j]; - if (option == null) - continue; - - if (i == words.Length - 1) - { - options[j] = option.Value.ToLower().Contains(word.ToLower()) ? option : null; - } - else + if (options[i] is { } option) { - options[j] = option.Value.Equals(word, StringComparison.InvariantCultureIgnoreCase) ? option.Next : null; + if (i == words.Length - 1) + { + options[j] = option.Value.ToLower().Contains(word.ToLower()) ? option : null; + } + else + { + options[j] = option.Value.Equals(word, StringComparison.InvariantCultureIgnoreCase) ? option.Next : null; + } } } } diff --git a/samples/ControlCatalog/Pages/ButtonSpinnerPage.xaml.cs b/samples/ControlCatalog/Pages/ButtonSpinnerPage.xaml.cs index 5c584b8781..e7450075ad 100644 --- a/samples/ControlCatalog/Pages/ButtonSpinnerPage.xaml.cs +++ b/samples/ControlCatalog/Pages/ButtonSpinnerPage.xaml.cs @@ -21,20 +21,23 @@ namespace ControlCatalog.Pages public void OnSpin(object sender, SpinEventArgs e) { var spinner = (ButtonSpinner)sender; - var txtBox = (TextBlock)spinner.Content; - int value = Array.IndexOf(_mountains, txtBox?.Text); - if (e.Direction == SpinDirection.Increase) - value++; - else - value--; + if (spinner.Content is TextBlock txtBox) + { + int value = Array.IndexOf(_mountains, txtBox.Text); + if (e.Direction == SpinDirection.Increase) + value++; + else + value--; - if (value < 0) - value = _mountains.Length - 1; - else if (value >= _mountains.Length) - value = 0; + if (value < 0) + value = _mountains.Length - 1; + else if (value >= _mountains.Length) + value = 0; + + txtBox.Text = _mountains[value]; + } - txtBox.Text = _mountains[value]; } private readonly string[] _mountains = new[] diff --git a/samples/ControlCatalog/Pages/ButtonsPage.xaml.cs b/samples/ControlCatalog/Pages/ButtonsPage.xaml.cs index 3e748dd6f6..2d63f1fee9 100644 --- a/samples/ControlCatalog/Pages/ButtonsPage.xaml.cs +++ b/samples/ControlCatalog/Pages/ButtonsPage.xaml.cs @@ -19,7 +19,7 @@ namespace ControlCatalog.Pages AvaloniaXamlLoader.Load(this); } - public void OnRepeatButtonClick(object sender, object args) + public void OnRepeatButtonClick(object? sender, object args) { repeatButtonClickCount++; var textBlock = this.Get("RepeatButtonTextBlock"); diff --git a/samples/ControlCatalog/Pages/CarouselPage.xaml.cs b/samples/ControlCatalog/Pages/CarouselPage.xaml.cs index 5b74e3e19e..c6aab5c4d5 100644 --- a/samples/ControlCatalog/Pages/CarouselPage.xaml.cs +++ b/samples/ControlCatalog/Pages/CarouselPage.xaml.cs @@ -33,7 +33,7 @@ namespace ControlCatalog.Pages } - private void TransitionChanged(object sender, SelectionChangedEventArgs e) + private void TransitionChanged(object? sender, SelectionChangedEventArgs e) { switch (_transition.SelectedIndex) { diff --git a/samples/ControlCatalog/Pages/ClipboardPage.xaml.cs b/samples/ControlCatalog/Pages/ClipboardPage.xaml.cs index eed46265ff..ef3d2bbafa 100644 --- a/samples/ControlCatalog/Pages/ClipboardPage.xaml.cs +++ b/samples/ControlCatalog/Pages/ClipboardPage.xaml.cs @@ -23,55 +23,79 @@ namespace ControlCatalog.Pages AvaloniaXamlLoader.Load(this); } - private async void CopyText(object sender, RoutedEventArgs args) + private async void CopyText(object? sender, RoutedEventArgs args) { - await Application.Current.Clipboard.SetTextAsync(ClipboardContent.Text); + if (Application.Current!.Clipboard is { } clipboard && ClipboardContent is { } clipboardContent) + await clipboard.SetTextAsync(clipboardContent.Text ?? String.Empty); } - private async void PasteText(object sender, RoutedEventArgs args) + private async void PasteText(object? sender, RoutedEventArgs args) { - ClipboardContent.Text = await Application.Current.Clipboard.GetTextAsync(); + if(Application.Current!.Clipboard is { } clipboard) + { + ClipboardContent.Text = await clipboard.GetTextAsync(); + } } - private async void CopyTextDataObject(object sender, RoutedEventArgs args) + private async void CopyTextDataObject(object? sender, RoutedEventArgs args) { - var dataObject = new DataObject(); - dataObject.Set(DataFormats.Text, ClipboardContent.Text ?? string.Empty); - await Application.Current.Clipboard.SetDataObjectAsync(dataObject); + if (Application.Current!.Clipboard is { } clipboard) + { + var dataObject = new DataObject(); + dataObject.Set(DataFormats.Text, ClipboardContent.Text ?? string.Empty); + await clipboard.SetDataObjectAsync(dataObject); + } } - private async void PasteTextDataObject(object sender, RoutedEventArgs args) + private async void PasteTextDataObject(object? sender, RoutedEventArgs args) { - ClipboardContent.Text = await Application.Current.Clipboard.GetDataAsync(DataFormats.Text) as string ?? string.Empty; + if (Application.Current!.Clipboard is { } clipboard) + { + ClipboardContent.Text = await clipboard.GetDataAsync(DataFormats.Text) as string ?? string.Empty; + } } - private async void CopyFilesDataObject(object sender, RoutedEventArgs args) + private async void CopyFilesDataObject(object? sender, RoutedEventArgs args) { - var files = ClipboardContent.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); - if (files.Length == 0) + if (Application.Current!.Clipboard is { } clipboard) { - return; + var files = (ClipboardContent.Text ?? String.Empty) + .Split(new[] { Environment.NewLine }, StringSplitOptions.RemoveEmptyEntries); + if (files.Length == 0) + { + return; + } + var dataObject = new DataObject(); + dataObject.Set(DataFormats.FileNames, files); + await clipboard.SetDataObjectAsync(dataObject); } - var dataObject = new DataObject(); - dataObject.Set(DataFormats.FileNames, files); - await Application.Current.Clipboard.SetDataObjectAsync(dataObject); } - private async void PasteFilesDataObject(object sender, RoutedEventArgs args) + private async void PasteFilesDataObject(object? sender, RoutedEventArgs args) { - var fiels = await Application.Current.Clipboard.GetDataAsync(DataFormats.FileNames) as IEnumerable; - ClipboardContent.Text = fiels != null ? string.Join(Environment.NewLine, fiels) : string.Empty; + if (Application.Current!.Clipboard is { } clipboard) + { + var fiels = await clipboard.GetDataAsync(DataFormats.FileNames) as IEnumerable; + ClipboardContent.Text = fiels != null ? string.Join(Environment.NewLine, fiels) : string.Empty; + } } private async void GetFormats(object sender, RoutedEventArgs args) { - var formats = await Application.Current.Clipboard.GetFormatsAsync(); - ClipboardContent.Text = string.Join(Environment.NewLine, formats); + if (Application.Current!.Clipboard is { } clipboard) + { + var formats = await clipboard.GetFormatsAsync(); + ClipboardContent.Text = string.Join(Environment.NewLine, formats); + } } private async void Clear(object sender, RoutedEventArgs args) { - await Application.Current.Clipboard.ClearAsync(); + if (Application.Current!.Clipboard is { } clipboard) + { + await clipboard.ClearAsync(); + } + } } } diff --git a/samples/ControlCatalog/Pages/ComboBoxPage.xaml.cs b/samples/ControlCatalog/Pages/ComboBoxPage.xaml.cs index d304bf227d..6d624c9a07 100644 --- a/samples/ControlCatalog/Pages/ComboBoxPage.xaml.cs +++ b/samples/ControlCatalog/Pages/ComboBoxPage.xaml.cs @@ -17,7 +17,7 @@ namespace ControlCatalog.Pages private void InitializeComponent() { AvaloniaXamlLoader.Load(this); - var fontComboBox = this.Find("fontComboBox"); + var fontComboBox = this.Get("fontComboBox"); fontComboBox.Items = FontManager.Current.GetInstalledFontFamilyNames().Select(x => new FontFamily(x)); fontComboBox.SelectedIndex = 0; } diff --git a/samples/ControlCatalog/Pages/CompositionPage.axaml.cs b/samples/ControlCatalog/Pages/CompositionPage.axaml.cs index 18069ca857..61e0ed5acb 100644 --- a/samples/ControlCatalog/Pages/CompositionPage.axaml.cs +++ b/samples/ControlCatalog/Pages/CompositionPage.axaml.cs @@ -1,14 +1,8 @@ using System; using System.Collections.Generic; -using System.Linq; -using System.Numerics; -using System.Threading.Tasks; using Avalonia; using Avalonia.Controls; -using Avalonia.Controls.Primitives; -using Avalonia.Interactivity; using Avalonia.Markup.Xaml; -using Avalonia.Markup.Xaml.Templates; using Avalonia.Media; using Avalonia.Rendering.Composition; using Avalonia.Rendering.Composition.Animations; @@ -18,7 +12,7 @@ namespace ControlCatalog.Pages; public partial class CompositionPage : UserControl { - private ImplicitAnimationCollection _implicitAnimations; + private ImplicitAnimationCollection? _implicitAnimations; public CompositionPage() { @@ -28,7 +22,7 @@ public partial class CompositionPage : UserControl protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e) { base.OnAttachedToVisualTree(e); - this.FindControl("Items").Items = CreateColorItems(); + this.Get("Items").Items = CreateColorItems(); } private List CreateColorItems() @@ -115,7 +109,6 @@ public partial class CompositionPage : UserControl public static void SetEnableAnimations(Border border, bool value) { - var page = border.FindAncestorOfType(); if (page == null) { @@ -127,8 +120,11 @@ public partial class CompositionPage : UserControl return; page.EnsureImplicitAnimations(); - ElementComposition.GetElementVisual((Visual)border.GetVisualParent()).ImplicitAnimations = - page._implicitAnimations; + if (border.GetVisualParent() is Visual visualParent + && ElementComposition.GetElementVisual(visualParent) is CompositionVisual compositionVisual) + { + compositionVisual.ImplicitAnimations = page._implicitAnimations; + } } } @@ -150,4 +146,4 @@ public class CompositionPageColorItem { Color = color; } -} \ No newline at end of file +} diff --git a/samples/ControlCatalog/Pages/ContextFlyoutPage.xaml.cs b/samples/ControlCatalog/Pages/ContextFlyoutPage.xaml.cs index 4d72fc5311..8bd1f4d85a 100644 --- a/samples/ControlCatalog/Pages/ContextFlyoutPage.xaml.cs +++ b/samples/ControlCatalog/Pages/ContextFlyoutPage.xaml.cs @@ -52,13 +52,13 @@ namespace ControlCatalog.Pages base.OnDataContextChanged(e); } - private void ContextFlyoutPage_Closing(object sender, CancelEventArgs e) + private void ContextFlyoutPage_Closing(object? sender, CancelEventArgs e) { var cancelCloseCheckBox = this.FindControl("CancelCloseCheckBox"); e.Cancel = cancelCloseCheckBox?.IsChecked ?? false; } - private void ContextFlyoutPage_Opening(object sender, EventArgs e) + private void ContextFlyoutPage_Opening(object? sender, EventArgs e) { if (e is CancelEventArgs cancelArgs) { @@ -67,20 +67,20 @@ namespace ControlCatalog.Pages } } - private void CloseFlyout(object sender, RoutedEventArgs e) + private void CloseFlyout(object? sender, RoutedEventArgs e) { _textBox.ContextFlyout?.Hide(); } - public void CustomContextRequested(object sender, ContextRequestedEventArgs e) + public void CustomContextRequested(object? sender, ContextRequestedEventArgs e) { - var border = (Border)sender; - var textBlock = (TextBlock)border.Child; - - textBlock.Text = e.TryGetPosition(border, out var point) - ? $"Context was requested with pointer at: {point.X:N0}, {point.Y:N0}" - : "Context was requested without pointer"; - e.Handled = true; + if (sender is Border border && border.Child is TextBlock textBlock) + { + textBlock.Text = e.TryGetPosition(border, out var point) + ? $"Context was requested with pointer at: {point.X:N0}, {point.Y:N0}" + : "Context was requested without pointer"; + e.Handled = true; + } } private void InitializeComponent() diff --git a/samples/ControlCatalog/Pages/ContextMenuPage.xaml.cs b/samples/ControlCatalog/Pages/ContextMenuPage.xaml.cs index 4581642024..96fcb54650 100644 --- a/samples/ControlCatalog/Pages/ContextMenuPage.xaml.cs +++ b/samples/ControlCatalog/Pages/ContextMenuPage.xaml.cs @@ -35,30 +35,31 @@ namespace ControlCatalog.Pages base.OnDataContextChanged(e); } - private void ContextFlyoutPage_Closing(object sender, CancelEventArgs e) + private void ContextFlyoutPage_Closing(object? sender, CancelEventArgs e) { var cancelCloseCheckBox = this.FindControl("CancelCloseCheckBox"); - e.Cancel = cancelCloseCheckBox.IsChecked ?? false; + e.Cancel = cancelCloseCheckBox?.IsChecked ?? false; } - private void ContextFlyoutPage_Opening(object sender, EventArgs e) + private void ContextFlyoutPage_Opening(object? sender, EventArgs e) { if (e is CancelEventArgs cancelArgs) { var cancelCloseCheckBox = this.FindControl("CancelOpenCheckBox"); - cancelArgs.Cancel = cancelCloseCheckBox.IsChecked ?? false; + cancelArgs.Cancel = cancelCloseCheckBox?.IsChecked ?? false; } } - public void CustomContextRequested(object sender, ContextRequestedEventArgs e) + public void CustomContextRequested(object? sender, ContextRequestedEventArgs e) { - var border = (Border)sender; - var textBlock = (TextBlock)border.Child; + if (sender is Border border && border.Child is TextBlock textBlock) + { + textBlock.Text = e.TryGetPosition(border, out var point) + ? $"Context was requested with pointer at: {point.X:N0}, {point.Y:N0}" + : "Context was requested without pointer"; + e.Handled = true; + } - textBlock.Text = e.TryGetPosition(border, out var point) - ? $"Context was requested with pointer at: {point.X:N0}, {point.Y:N0}" - : "Context was requested without pointer"; - e.Handled = true; } private void InitializeComponent() diff --git a/samples/ControlCatalog/Pages/DataGridPage.xaml.cs b/samples/ControlCatalog/Pages/DataGridPage.xaml.cs index 219b7aeac4..3565d113bc 100644 --- a/samples/ControlCatalog/Pages/DataGridPage.xaml.cs +++ b/samples/ControlCatalog/Pages/DataGridPage.xaml.cs @@ -62,7 +62,7 @@ namespace ControlCatalog.Pages addButton.Click += (a, b) => collectionView3.AddNew(); } - private void Dg1_LoadingRow(object sender, DataGridRowEventArgs e) + private void Dg1_LoadingRow(object? sender, DataGridRowEventArgs e) { e.Row.Header = e.Row.GetIndex() + 1; } @@ -74,7 +74,7 @@ namespace ControlCatalog.Pages private class ReversedStringComparer : IComparer, IComparer { - public int Compare(object x, object y) + public int Compare(object? x, object? y) { if (x is string left && y is string right) { diff --git a/samples/ControlCatalog/Pages/DialogsPage.xaml.cs b/samples/ControlCatalog/Pages/DialogsPage.xaml.cs index 036dccde0e..67e9ef4e40 100644 --- a/samples/ControlCatalog/Pages/DialogsPage.xaml.cs +++ b/samples/ControlCatalog/Pages/DialogsPage.xaml.cs @@ -111,9 +111,16 @@ namespace ControlCatalog.Pages Title = "Select folder", Directory = lastSelectedDirectory?.TryGetUri(out var path) == true ? path.LocalPath : null }.ShowAsync(GetWindow()); - lastSelectedDirectory = new BclStorageFolder(new System.IO.DirectoryInfo(result)); - results.Items = new [] { result }; - resultsVisible.IsVisible = result != null; + if (string.IsNullOrEmpty(result)) + { + resultsVisible.IsVisible = false; + } + else + { + lastSelectedDirectory = new BclStorageFolder(new System.IO.DirectoryInfo(result)); + results.Items = new[] { result }; + resultsVisible.IsVisible = true; + } }; this.Get