Browse Source

Merge branch 'master' into fixes/Samples/RenderDemo

pull/8719/head
Max Katz 4 years ago
committed by GitHub
parent
commit
f21491ec7e
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 6
      samples/ControlCatalog/MainView.xaml.cs
  2. 8
      samples/ControlCatalog/Models/Person.cs
  3. 2
      samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml
  4. 24
      samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml.cs
  5. 25
      samples/ControlCatalog/Pages/ButtonSpinnerPage.xaml.cs
  6. 2
      samples/ControlCatalog/Pages/ButtonsPage.xaml.cs
  7. 2
      samples/ControlCatalog/Pages/CarouselPage.xaml.cs
  8. 70
      samples/ControlCatalog/Pages/ClipboardPage.xaml.cs
  9. 2
      samples/ControlCatalog/Pages/ComboBoxPage.xaml.cs
  10. 20
      samples/ControlCatalog/Pages/CompositionPage.axaml.cs
  11. 22
      samples/ControlCatalog/Pages/ContextFlyoutPage.xaml.cs
  12. 23
      samples/ControlCatalog/Pages/ContextMenuPage.xaml.cs
  13. 4
      samples/ControlCatalog/Pages/DataGridPage.xaml.cs
  14. 13
      samples/ControlCatalog/Pages/DialogsPage.xaml.cs
  15. 20
      samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs
  16. 2
      samples/ControlCatalog/Pages/FlyoutsPage.axaml.cs
  17. 10
      samples/ControlCatalog/Pages/ItemsRepeaterPage.xaml.cs
  18. 6
      samples/ControlCatalog/Pages/NumericUpDownPage.xaml.cs
  19. 6
      samples/ControlCatalog/Pages/OpenGlPage.xaml.cs
  20. 31
      samples/ControlCatalog/Pages/PointersPage.xaml.cs
  21. 6
      samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs
  22. 36
      samples/IntegrationTestApp/MainWindow.axaml.cs
  23. 11
      src/Avalonia.Controls/AutoCompleteBox.cs
  24. 77
      src/Avalonia.Controls/Calendar/Calendar.cs
  25. 71
      src/Avalonia.Controls/Calendar/CalendarItem.cs
  26. 2
      src/Avalonia.Controls/Calendar/SelectedDatesCollection.cs
  27. 2
      src/Skia/Avalonia.Skia/Gpu/OpenGl/OpenGlBitmapImpl.cs

6
samples/ControlCatalog/MainView.xaml.cs

@ -22,8 +22,8 @@ namespace ControlCatalog
if (AvaloniaLocator.Current?.GetService<IRuntimePlatform>()?.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)

8
samples/ControlCatalog/Models/Person.cs

@ -85,7 +85,7 @@ namespace ControlCatalog.Models
}
else
{
if (_errorLookup.TryGetValue(propertyName, out List<string> 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<string> errorList))
if (propertyName is { } && _errorLookup.TryGetValue(propertyName, out var errorList))
return errorList;
else
return null;
return Array.Empty<object>();
}
}
}

2
samples/ControlCatalog/Pages/AutoCompleteBoxPage.xaml

@ -28,7 +28,7 @@
</StackPanel>
<StackPanel>
<TextBlock Text="MinimumPopulateDelay: 1s" />
<AutoCompleteBox MinimumPopulateDelay="1" />
<AutoCompleteBox MinimumPopulateDelay="00:00:01" />
</StackPanel>
<StackPanel>
<TextBlock Text="MaxDropDownHeight: 60" />

24
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<string>();
var options = Sentences.Select(x => x.First).ToArray();
var options = Sentences.Select(x => x.First)
.ToArray<LinkedListNode<string>?>();
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;
}
}
}
}

25
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[]

2
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<TextBlock>("RepeatButtonTextBlock");

2
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)
{

70
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<string>;
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<string>;
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();
}
}
}
}

2
samples/ControlCatalog/Pages/ComboBoxPage.xaml.cs

@ -17,7 +17,7 @@ namespace ControlCatalog.Pages
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
var fontComboBox = this.Find<ComboBox>("fontComboBox");
var fontComboBox = this.Get<ComboBox>("fontComboBox");
fontComboBox.Items = FontManager.Current.GetInstalledFontFamilyNames().Select(x => new FontFamily(x));
fontComboBox.SelectedIndex = 0;
}

20
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<ItemsControl>("Items").Items = CreateColorItems();
this.Get<ItemsControl>("Items").Items = CreateColorItems();
}
private List<CompositionPageColorItem> CreateColorItems()
@ -115,7 +109,6 @@ public partial class CompositionPage : UserControl
public static void SetEnableAnimations(Border border, bool value)
{
var page = border.FindAncestorOfType<CompositionPage>();
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;
}
}
}

22
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<CheckBox>("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()

23
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<CheckBox>("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<CheckBox>("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()

4
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<object>, IComparer
{
public int Compare(object x, object y)
public int Compare(object? x, object? y)
{
if (x is string left && y is string right)
{

13
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<Button>("OpenBoth").Click += async delegate
{

20
samples/ControlCatalog/Pages/DragAndDropPage.xaml.cs

@ -1,9 +1,9 @@
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
using System;
using System;
using System.Linq;
using System.Reflection;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Markup.Xaml;
namespace ControlCatalog.Pages
{
@ -27,9 +27,9 @@ namespace ControlCatalog.Pages
void SetupDnd(string suffix, Action<DataObject> factory, DragDropEffects effects)
{
var dragMe = this.Get<Border>("DragMe" + suffix);
var dragState = this.Get<TextBlock>("DragState"+suffix);
var dragState = this.Get<TextBlock>("DragState" + suffix);
async void DoDrag(object sender, Avalonia.Input.PointerPressedEventArgs e)
async void DoDrag(object? sender, Avalonia.Input.PointerPressedEventArgs e)
{
var dragData = new DataObject();
factory(dragData);
@ -55,7 +55,7 @@ namespace ControlCatalog.Pages
}
}
void DragOver(object sender, DragEventArgs e)
void DragOver(object? sender, DragEventArgs e)
{
if (e.Source is Control c && c.Name == "MoveTarget")
{
@ -73,7 +73,7 @@ namespace ControlCatalog.Pages
e.DragEffects = DragDropEffects.None;
}
void Drop(object sender, DragEventArgs e)
void Drop(object? sender, DragEventArgs e)
{
if (e.Source is Control c && c.Name == "MoveTarget")
{
@ -83,11 +83,11 @@ namespace ControlCatalog.Pages
{
e.DragEffects = e.DragEffects & (DragDropEffects.Copy);
}
if (e.Data.Contains(DataFormats.Text))
_DropState.Text = e.Data.GetText();
else if (e.Data.Contains(DataFormats.FileNames))
_DropState.Text = string.Join(Environment.NewLine, e.Data.GetFileNames());
_DropState.Text = string.Join(Environment.NewLine, e.Data.GetFileNames() ?? Array.Empty<string>());
else if (e.Data.Contains(CustomFormat))
_DropState.Text = "Custom: " + e.Data.Get(CustomFormat);
}

2
samples/ControlCatalog/Pages/FlyoutsPage.axaml.cs

@ -20,7 +20,7 @@ namespace ControlCatalog.Pages
SetXamlTexts();
}
private void Afp_DoubleTapped(object sender, RoutedEventArgs e)
private void Afp_DoubleTapped(object? sender, RoutedEventArgs e)
{
if (sender is Panel p)
{

10
samples/ControlCatalog/Pages/ItemsRepeaterPage.xaml.cs

@ -123,7 +123,7 @@ namespace ControlCatalog.Pages
element.BringIntoView();
}
private void RepeaterClick(object sender, PointerPressedEventArgs e)
private void RepeaterClick(object? sender, PointerPressedEventArgs e)
{
if ((e.Source as TextBlock)?.DataContext is ItemsRepeaterPageViewModel.Item item)
{
@ -132,7 +132,7 @@ namespace ControlCatalog.Pages
}
}
private void RepeaterOnKeyDown(object sender, KeyEventArgs e)
private void RepeaterOnKeyDown(object? sender, KeyEventArgs e)
{
if (e.Key == Key.F5)
{
@ -140,17 +140,17 @@ namespace ControlCatalog.Pages
}
}
private void scrollToLast_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
private void scrollToLast_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
ScrollTo(_viewModel.Items.Count - 1);
}
private void scrollToRandom_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
private void scrollToRandom_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
ScrollTo(_random.Next(_viewModel.Items.Count - 1));
}
private void scrollToSelected_Click(object sender, Avalonia.Interactivity.RoutedEventArgs e)
private void scrollToSelected_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
ScrollTo(_selectedIndex);
}

6
samples/ControlCatalog/Pages/NumericUpDownPage.xaml.cs

@ -2,9 +2,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Markup.Xaml;
using MiniMvvm;
@ -29,7 +27,7 @@ namespace ControlCatalog.Pages
public class NumbersPageViewModel : ViewModelBase
{
private IList<FormatObject>? _formats;
private FormatObject _selectedFormat;
private FormatObject? _selectedFormat;
private IList<Location>? _spinnerLocations;
private double _doubleValue;
@ -89,7 +87,7 @@ namespace ControlCatalog.Pages
.Where(c => new[] { "en-US", "en-GB", "fr-FR", "ar-DZ", "zh-CH", "cs-CZ" }.Contains(c.Name))
.ToArray();
public FormatObject SelectedFormat
public FormatObject? SelectedFormat
{
get { return _selectedFormat; }
set { this.RaiseAndSetIfChanged(ref _selectedFormat, value); }

6
samples/ControlCatalog/Pages/OpenGlPage.xaml.cs

@ -68,7 +68,7 @@ namespace ControlCatalog.Pages
set => SetAndRaise(DiscoProperty, ref _disco, value);
}
private string _info;
private string _info = string.Empty;
public static readonly DirectProperty<OpenGlPageControl, string> InfoProperty =
AvaloniaProperty.RegisterDirect<OpenGlPageControl, string>("Info", o => o.Info, (o, v) => o.Info = v);
@ -205,7 +205,7 @@ namespace ControlCatalog.Pages
public OpenGlPageControl()
{
var name = typeof(OpenGlPage).Assembly.GetManifestResourceNames().First(x => x.Contains("teapot.bin"));
using (var sr = new BinaryReader(typeof(OpenGlPage).Assembly.GetManifestResourceStream(name)))
using (var sr = new BinaryReader(typeof(OpenGlPage).Assembly.GetManifestResourceStream(name)!))
{
var buf = new byte[sr.ReadInt32()];
sr.Read(buf, 0, buf.Length);
@ -345,7 +345,7 @@ namespace ControlCatalog.Pages
0.01f, 1000);
var view = Matrix4x4.CreateLookAt(new Vector3(25, 25, 25), new Vector3(), new Vector3(0, -1, 0));
var view = Matrix4x4.CreateLookAt(new Vector3(25, 25, 25), new Vector3(), new Vector3(0, 1, 0));
var model = Matrix4x4.CreateFromYawPitchRoll(_yaw, _pitch, _roll);
var modelLoc = GL.GetUniformLocationString(_shaderProgram, "uModel");
var viewLoc = GL.GetUniformLocationString(_shaderProgram, "uView");

31
samples/ControlCatalog/Pages/PointersPage.xaml.cs

@ -1,8 +1,6 @@
using System;
using Avalonia;
using Avalonia.Controls;
using Avalonia.Input;
using Avalonia.Interactivity;
using Avalonia.Markup.Xaml;
namespace ControlCatalog.Pages;
@ -31,28 +29,33 @@ public class PointersPage : UserControl
border2.PointerExited += Border_PointerUpdated;
}
private void Border_PointerUpdated(object sender, PointerEventArgs e)
private void Border_PointerUpdated(object? sender, PointerEventArgs e)
{
var textBlock = (TextBlock)((Border)sender).Child;
var position = e.GetPosition((Border)sender);
textBlock.Text = @$"Type: {e.Pointer.Type}
if (sender is Border border && border.Child is TextBlock textBlock)
{
var position = e.GetPosition(border);
textBlock.Text = @$"Type: {e.Pointer.Type}
Captured: {e.Pointer.Captured == sender}
PointerId: {e.Pointer.Id}
Position: {(int)position.X} {(int)position.Y}";
e.Handled = true;
e.Handled = true;
}
}
private void Border_PointerCaptureLost(object sender, PointerCaptureLostEventArgs e)
private void Border_PointerCaptureLost(object? sender, PointerCaptureLostEventArgs e)
{
var textBlock = (TextBlock)((Border)sender).Child;
textBlock.Text = @$"Type: {e.Pointer.Type}
if (sender is Border border && border.Child is TextBlock textBlock)
{
textBlock.Text = @$"Type: {e.Pointer.Type}
Captured: {e.Pointer.Captured == sender}
PointerId: {e.Pointer.Id}
Position: ??? ???";
e.Handled = true;
e.Handled = true;
}
}
private void Border_PointerReleased(object sender, PointerReleasedEventArgs e)
private void Border_PointerReleased(object? sender, PointerReleasedEventArgs e)
{
if (e.Pointer.Captured == sender)
{
@ -65,9 +68,9 @@ Position: ??? ???";
}
}
private void Border_PointerPressed(object sender, PointerPressedEventArgs e)
private void Border_PointerPressed(object? sender, PointerPressedEventArgs e)
{
e.Pointer.Capture((Border)sender);
e.Pointer.Capture(sender as Border);
e.Handled = true;
}

6
samples/ControlCatalog/ViewModels/TransitioningContentControlPageViewModel.cs

@ -117,9 +117,9 @@ namespace ControlCatalog.ViewModels
PageTransitions[3].Transition = new PageSlide(TimeSpan.FromMilliseconds(Duration), PageSlide.SlideAxis.Vertical);
var compositeTransition = new CompositePageTransition();
compositeTransition.PageTransitions.Add(PageTransitions[1].Transition);
compositeTransition.PageTransitions.Add(PageTransitions[2].Transition);
compositeTransition.PageTransitions.Add(PageTransitions[3].Transition);
compositeTransition.PageTransitions.Add(PageTransitions[1].Transition!);
compositeTransition.PageTransitions.Add(PageTransitions[2].Transition!);
compositeTransition.PageTransitions.Add(PageTransitions[3].Transition!);
PageTransitions[4].Transition = compositeTransition;
PageTransitions[5].Transition = new CustomTransition(TimeSpan.FromMilliseconds(Duration));

36
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")

11
src/Avalonia.Controls/AutoCompleteBox.cs

@ -392,6 +392,8 @@ namespace Avalonia.Controls
private AutoCompleteSelector<object>? _itemSelector;
private AutoCompleteSelector<string?>? _textSelector;
private readonly EventHandler _populateDropDownHandler;
public static readonly RoutedEvent<SelectionChangedEventArgs> SelectionChangedEvent =
RoutedEvent.Register<SelectionChangedEventArgs>(nameof(SelectionChanged), RoutingStrategies.Bubble, typeof(AutoCompleteBox));
@ -668,6 +670,7 @@ namespace Avalonia.Controls
if (newValue == TimeSpan.Zero)
{
_delayTimer.Tick -= _populateDropDownHandler;
_delayTimer = null;
}
}
@ -678,7 +681,7 @@ namespace Avalonia.Controls
if (_delayTimer == null)
{
_delayTimer = new DispatcherTimer();
_delayTimer.Tick += PopulateDropDown;
_delayTimer.Tick += _populateDropDownHandler;
}
// Set the new tick interval
@ -864,6 +867,7 @@ namespace Avalonia.Controls
/// </summary>
public AutoCompleteBox()
{
_populateDropDownHandler = PopulateDropDown;
ClearView();
}
@ -1771,10 +1775,7 @@ namespace Avalonia.Controls
/// <param name="e">The event arguments.</param>
private void PopulateDropDown(object? sender, EventArgs e)
{
if (_delayTimer != null)
{
_delayTimer.Stop();
}
_delayTimer?.Stop();
// Update the prefix/search text.
SearchText = Text;

77
src/Avalonia.Controls/Calendar/Calendar.cs

@ -224,7 +224,7 @@ namespace Avalonia.Controls
/// </para>
/// </remarks>
[TemplatePart(PART_ElementMonth, typeof(CalendarItem))]
[TemplatePart(PART_ElementRoot, typeof(Panel))]
[TemplatePart(PART_ElementRoot, typeof(Panel))]
public class Calendar : TemplatedControl
{
internal const int RowsPerMonth = 7;
@ -338,14 +338,11 @@ namespace Avalonia.Controls
/// <param name="e">The DependencyPropertyChangedEventArgs.</param>
private void OnIsTodayHighlightedChanged(AvaloniaPropertyChangedEventArgs e)
{
if (DisplayDate != null)
{
int i = DateTimeHelper.CompareYearMonth(DisplayDateInternal, DateTime.Today);
int i = DateTimeHelper.CompareYearMonth(DisplayDateInternal, DateTime.Today);
if (i > -2 && i < 2)
{
UpdateMonths();
}
if (i > -2 && i < 2)
{
UpdateMonths();
}
}
@ -655,7 +652,7 @@ namespace Avalonia.Controls
SelectedDatesChanged?.Invoke(this, e);
}
}
internal Collection<DateTime> RemovedItems { get; set; }
internal DateTime? LastSelectedDateInternal { get; set; }
internal DateTime? LastSelectedDate
@ -914,7 +911,7 @@ namespace Avalonia.Controls
o => o.DisplayDateEnd,
(o, v) => o.DisplayDateEnd = v,
defaultBindingMode: BindingMode.TwoWay);
/// <summary>
/// Gets or sets the last date to be displayed.
/// </summary>
@ -1242,7 +1239,7 @@ namespace Avalonia.Controls
{
b.IsSelected = false;
}
}
}
}
}
}
@ -1278,7 +1275,7 @@ namespace Avalonia.Controls
internal void OnPreviousClick()
{
if (DisplayMode == CalendarMode.Month && DisplayDate != null)
if (DisplayMode == CalendarMode.Month)
{
DateTime? d = DateTimeHelper.AddMonths(DateTimeHelper.DiscardDayTime(DisplayDate), -1);
if (d.HasValue)
@ -1326,7 +1323,7 @@ namespace Avalonia.Controls
}
internal void OnNextClick()
{
if (DisplayMode == CalendarMode.Month && DisplayDate != null)
if (DisplayMode == CalendarMode.Month)
{
DateTime? d = DateTimeHelper.AddMonths(DateTimeHelper.DiscardDayTime(DisplayDate), 1);
if (d.HasValue)
@ -1645,7 +1642,7 @@ namespace Avalonia.Controls
{
if (DisplayMode == CalendarMode.Month)
{
if (LastSelectedDate.HasValue && DisplayDateInternal != null)
if (LastSelectedDate.HasValue)
{
// If a blackout day is inactive, when clicked on it, the
// previous inactive day which is not a blackout day can get
@ -1897,24 +1894,21 @@ namespace Avalonia.Controls
{
case CalendarMode.Month:
{
if (DisplayDate != null)
{
DateTime? selectedDate = new DateTime(DisplayDateInternal.Year, DisplayDateInternal.Month, 1);
DateTime? selectedDate = new DateTime(DisplayDateInternal.Year, DisplayDateInternal.Month, 1);
if (DateTimeHelper.CompareYearMonth(DateTime.MaxValue, selectedDate.Value) > 0)
{
// since DisplayDate is not equal to
// DateTime.MaxValue we are sure selectedDate is\
// not null
selectedDate = DateTimeHelper.AddMonths(selectedDate.Value, 1)!.Value;
selectedDate = DateTimeHelper.AddDays(selectedDate.Value, -1)!.Value;
}
else
{
selectedDate = DateTime.MaxValue;
}
ProcessSelection(shift, selectedDate, null);
if (DateTimeHelper.CompareYearMonth(DateTime.MaxValue, selectedDate.Value) > 0)
{
// since DisplayDate is not equal to
// DateTime.MaxValue we are sure selectedDate is\
// not null
selectedDate = DateTimeHelper.AddMonths(selectedDate.Value, 1)!.Value;
selectedDate = DateTimeHelper.AddDays(selectedDate.Value, -1)!.Value;
}
else
{
selectedDate = DateTime.MaxValue;
}
ProcessSelection(shift, selectedDate, null);
break;
}
case CalendarMode.Year:
@ -2026,7 +2020,6 @@ namespace Avalonia.Controls
focusDate = DisplayDate;
LastSelectedDate = DisplayDate;
}
Debug.Assert(focusDate != null, "focusDate should not be null!");
FocusButton = FindDayButtonFromDay(focusDate);
if (FocusButton != null)
@ -2091,17 +2084,17 @@ namespace Avalonia.Controls
static Calendar()
{
IsEnabledProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnIsEnabledChanged(e));
FirstDayOfWeekProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnFirstDayOfWeekChanged(e));
IsTodayHighlightedProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnIsTodayHighlightedChanged(e));
DisplayModeProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnDisplayModePropertyChanged(e));
SelectionModeProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnSelectionModeChanged(e));
SelectedDateProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnSelectedDateChanged(e));
DisplayDateProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnDisplayDateChanged(e));
DisplayDateStartProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnDisplayDateStartChanged(e));
DisplayDateEndProperty.Changed.AddClassHandler<Calendar>((x,e) => x.OnDisplayDateEndChanged(e));
KeyDownEvent.AddClassHandler<Calendar>((x,e) => x.Calendar_KeyDown(e));
KeyUpEvent.AddClassHandler<Calendar>((x,e) => x.Calendar_KeyUp(e));
IsEnabledProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnIsEnabledChanged(e));
FirstDayOfWeekProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnFirstDayOfWeekChanged(e));
IsTodayHighlightedProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnIsTodayHighlightedChanged(e));
DisplayModeProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnDisplayModePropertyChanged(e));
SelectionModeProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnSelectionModeChanged(e));
SelectedDateProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnSelectedDateChanged(e));
DisplayDateProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnDisplayDateChanged(e));
DisplayDateStartProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnDisplayDateStartChanged(e));
DisplayDateEndProperty.Changed.AddClassHandler<Calendar>((x, e) => x.OnDisplayDateEndChanged(e));
KeyDownEvent.AddClassHandler<Calendar>((x, e) => x.Calendar_KeyDown(e));
KeyUpEvent.AddClassHandler<Calendar>((x, e) => x.Calendar_KeyUp(e));
}
/// <summary>

71
src/Avalonia.Controls/Calendar/CalendarItem.cs

@ -4,7 +4,6 @@
// All other rights reserved.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using Avalonia.Collections.Pooled;
@ -353,7 +352,6 @@ namespace Avalonia.Controls.Primitives
{
if (Owner != null)
{
Debug.Assert(Owner.DisplayDate != null, "The Owner Calendar's DisplayDate should not be null!");
_currentMonth = Owner.DisplayDateInternal;
}
else
@ -361,17 +359,14 @@ namespace Avalonia.Controls.Primitives
_currentMonth = DateTime.Today;
}
if (_currentMonth != null)
{
SetMonthModeHeaderButton();
SetMonthModePreviousButton(_currentMonth);
SetMonthModeNextButton(_currentMonth);
SetMonthModeHeaderButton();
SetMonthModePreviousButton(_currentMonth);
SetMonthModeNextButton(_currentMonth);
if (MonthView != null)
{
SetDayTitles();
SetCalendarDayButtons(_currentMonth);
}
if (MonthView != null)
{
SetDayTitles();
SetCalendarDayButtons(_currentMonth);
}
}
private void SetMonthModeHeaderButton()
@ -592,7 +587,6 @@ namespace Avalonia.Controls.Primitives
{
if (Owner != null)
{
Debug.Assert(Owner.SelectedMonth != null, "The Owner Calendar's SelectedMonth should not be null!");
_currentMonth = (DateTime)Owner.SelectedMonth;
}
else
@ -600,16 +594,13 @@ namespace Avalonia.Controls.Primitives
_currentMonth = DateTime.Today;
}
if (_currentMonth != null)
{
SetYearModeHeaderButton();
SetYearModePreviousButton();
SetYearModeNextButton();
SetYearModeHeaderButton();
SetYearModePreviousButton();
SetYearModeNextButton();
if (YearView != null)
{
SetMonthButtonsForYearMode();
}
if (YearView != null)
{
SetMonthButtonsForYearMode();
}
}
private void SetYearModeHeaderButton()
@ -660,7 +651,6 @@ namespace Avalonia.Controls.Primitives
childButton.IsCalendarButtonFocused = false;
}
Debug.Assert(Owner.DisplayDateInternal != null, "The Owner Calendar's DisplayDateInternal should not be null!");
childButton.IsSelected = (DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateInternal) == 0);
if (DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateRangeStart) < 0 || DateTimeHelper.CompareYearMonth(day, Owner.DisplayDateRangeEnd) > 0)
@ -685,7 +675,6 @@ namespace Avalonia.Controls.Primitives
if (Owner != null)
{
Debug.Assert(Owner.SelectedYear != null, "The owning Calendar's selected year should not be null!");
selectedYear = Owner.SelectedYear;
_currentMonth = (DateTime)Owner.SelectedMonth;
}
@ -695,19 +684,16 @@ namespace Avalonia.Controls.Primitives
selectedYear = DateTime.Today;
}
if (_currentMonth != null)
{
int decade = DateTimeHelper.DecadeOfDate(selectedYear);
int decadeEnd = DateTimeHelper.EndOfDecade(selectedYear);
int decade = DateTimeHelper.DecadeOfDate(selectedYear);
int decadeEnd = DateTimeHelper.EndOfDecade(selectedYear);
SetDecadeModeHeaderButton(decade, decadeEnd);
SetDecadeModePreviousButton(decade);
SetDecadeModeNextButton(decadeEnd);
SetDecadeModeHeaderButton(decade, decadeEnd);
SetDecadeModePreviousButton(decade);
SetDecadeModeNextButton(decadeEnd);
if (YearView != null)
{
SetYearButtons(decade, decadeEnd);
}
if (YearView != null)
{
SetYearButtons(decade, decadeEnd);
}
}
internal void UpdateYearViewSelection(CalendarButton calendarButton)
@ -822,22 +808,15 @@ namespace Avalonia.Controls.Primitives
{
if (Owner.DisplayMode == CalendarMode.Month)
{
if (Owner.DisplayDate != null)
{
d = Owner.DisplayDateInternal;
Owner.SelectedMonth = new DateTime(d.Year, d.Month, 1);
}
d = Owner.DisplayDateInternal;
Owner.SelectedMonth = new DateTime(d.Year, d.Month, 1);
Owner.DisplayMode = CalendarMode.Year;
}
else
{
Debug.Assert(Owner.DisplayMode == CalendarMode.Year, "The Owner Calendar's DisplayMode should be Year!");
if (Owner.SelectedMonth != null)
{
d = Owner.SelectedMonth;
Owner.SelectedYear = new DateTime(d.Year, d.Month, 1);
}
d = Owner.SelectedMonth;
Owner.SelectedYear = new DateTime(d.Year, d.Month, 1);
Owner.DisplayMode = CalendarMode.Decade;
}
}

2
src/Avalonia.Controls/Calendar/SelectedDatesCollection.cs

@ -297,7 +297,7 @@ namespace Avalonia.Controls.Primitives
}
else
{
if (item != null && DateTime.Compare(this[index], item) != 0 && Calendar.IsValidDateSelection(_owner, item))
if (DateTime.Compare(this[index], item) != 0 && Calendar.IsValidDateSelection(_owner, item))
{
removedItems.Add(this[index]);
base.SetItem(index, item);

2
src/Skia/Avalonia.Skia/Gpu/OpenGl/OpenGlBitmapImpl.cs

@ -41,7 +41,7 @@ namespace Avalonia.Skia
new GRGlTextureInfo(
GlConsts.GL_TEXTURE_2D, (uint)_surface.GetTextureId(),
(uint)_surface.InternalFormat)))
using (var surface = SKSurface.Create(context.GrContext, backendTexture, GRSurfaceOrigin.TopLeft,
using (var surface = SKSurface.Create(context.GrContext, backendTexture, GRSurfaceOrigin.BottomLeft,
SKColorType.Rgba8888))
{
// Again, silently ignore, if something went wrong it's not our fault

Loading…
Cancel
Save