fix: improve nullable annotation.
This commit is contained in:
parent
e193bfc697
commit
9f43baa039
@ -14,19 +14,19 @@ public class FunctionalColorGroupControl: TemplatedControl
|
||||
set => SetValue(TitleProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<FunctionalColorGroupControl, IEnumerable> LightColorsProperty = AvaloniaProperty.RegisterDirect<FunctionalColorGroupControl, IEnumerable>(
|
||||
public static readonly DirectProperty<FunctionalColorGroupControl, IEnumerable?> LightColorsProperty = AvaloniaProperty.RegisterDirect<FunctionalColorGroupControl, IEnumerable?>(
|
||||
nameof(LightColors), o => o.LightColors, (o, v) => o.LightColors = v);
|
||||
private IEnumerable _lightColors;
|
||||
public IEnumerable LightColors
|
||||
private IEnumerable? _lightColors;
|
||||
public IEnumerable? LightColors
|
||||
{
|
||||
get => _lightColors;
|
||||
set => SetAndRaise(LightColorsProperty, ref _lightColors, value);
|
||||
}
|
||||
|
||||
public static readonly DirectProperty<FunctionalColorGroupControl, IEnumerable> DarkColorsProperty = AvaloniaProperty.RegisterDirect<FunctionalColorGroupControl, IEnumerable>(
|
||||
public static readonly DirectProperty<FunctionalColorGroupControl, IEnumerable?> DarkColorsProperty = AvaloniaProperty.RegisterDirect<FunctionalColorGroupControl, IEnumerable?>(
|
||||
nameof(DarkColors), o => o.DarkColors, (o, v) => o.DarkColors = v);
|
||||
private IEnumerable _darkColors;
|
||||
public IEnumerable DarkColors
|
||||
private IEnumerable? _darkColors;
|
||||
public IEnumerable? DarkColors
|
||||
{
|
||||
get => _darkColors;
|
||||
set => SetAndRaise(DarkColorsProperty, ref _darkColors, value);
|
||||
|
@ -12,10 +12,10 @@ namespace Semi.Avalonia.Demo.ViewModels;
|
||||
public class PaletteDemoViewModel: ObservableObject
|
||||
{
|
||||
private readonly string[] _predefinedColorNames = { "Amber","Blue","Cyan","Green","Grey","Indigo","LightBlue","LightGreen","Lime","Orange","Pink","Purple","Red","Teal","Violet","Yellow" };
|
||||
private IResourceDictionary _lightResourceDictionary;
|
||||
private IResourceDictionary _darkResourceDictionary;
|
||||
private readonly IResourceDictionary? _lightResourceDictionary;
|
||||
private readonly IResourceDictionary? _darkResourceDictionary;
|
||||
|
||||
private ColorItemViewModel _selectedColor;
|
||||
private ColorItemViewModel _selectedColor = null!;
|
||||
|
||||
public ColorItemViewModel SelectedColor
|
||||
{
|
||||
@ -24,14 +24,14 @@ public class PaletteDemoViewModel: ObservableObject
|
||||
}
|
||||
|
||||
|
||||
private ObservableCollection<ColorListViewModel> _lightLists;
|
||||
public ObservableCollection<ColorListViewModel> LightLists
|
||||
private ObservableCollection<ColorListViewModel>? _lightLists;
|
||||
public ObservableCollection<ColorListViewModel>? LightLists
|
||||
{
|
||||
get => _lightLists;
|
||||
set => SetProperty(ref _lightLists, value);
|
||||
}
|
||||
private ObservableCollection<ColorListViewModel> _darkLists;
|
||||
public ObservableCollection<ColorListViewModel> DarkLists
|
||||
private ObservableCollection<ColorListViewModel>? _darkLists;
|
||||
public ObservableCollection<ColorListViewModel>? DarkLists
|
||||
{
|
||||
get => _darkLists;
|
||||
set => SetProperty(ref _darkLists, value);
|
||||
@ -41,8 +41,8 @@ public class PaletteDemoViewModel: ObservableObject
|
||||
|
||||
public PaletteDemoViewModel()
|
||||
{
|
||||
_lightResourceDictionary = (ResourceDictionary)AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Light/Palette.axaml"));
|
||||
_darkResourceDictionary = (ResourceDictionary)AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Dark/Palette.axaml"));
|
||||
_lightResourceDictionary = AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Light/Palette.axaml")) as ResourceDictionary;
|
||||
_darkResourceDictionary = AvaloniaXamlLoader.Load(new Uri("avares://Semi.Avalonia/Themes/Dark/Palette.axaml")) as ResourceDictionary;
|
||||
WeakReferenceMessenger.Default.Register<PaletteDemoViewModel, ColorItemViewModel>(this, OnClickColorItem);
|
||||
}
|
||||
|
||||
@ -110,8 +110,12 @@ public class ColorListViewModel: ObservableObject
|
||||
set => SetProperty(ref _seriesName, value);
|
||||
}
|
||||
|
||||
internal void Initialize(IResourceDictionary resourceDictionary, string color, bool light)
|
||||
internal void Initialize(IResourceDictionary? resourceDictionary, string color, bool light)
|
||||
{
|
||||
if (resourceDictionary is null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
SeriesName = color;
|
||||
Color = new ObservableCollection<ColorItemViewModel>();
|
||||
|
||||
@ -134,28 +138,28 @@ public class ColorListViewModel: ObservableObject
|
||||
public class ColorItemViewModel : ObservableObject
|
||||
{
|
||||
|
||||
private IBrush _brush;
|
||||
private IBrush _brush = null!;
|
||||
public IBrush Brush
|
||||
{
|
||||
get => _brush;
|
||||
set => SetProperty(ref _brush, value);
|
||||
}
|
||||
|
||||
private IBrush _textBrush;
|
||||
private IBrush _textBrush = null!;
|
||||
public IBrush TextBrush
|
||||
{
|
||||
get => _textBrush;
|
||||
set => SetProperty(ref _textBrush, value);
|
||||
}
|
||||
|
||||
private string _colorDisplayName;
|
||||
private string _colorDisplayName = null!;
|
||||
public string ColorDisplayName
|
||||
{
|
||||
get => _colorDisplayName;
|
||||
set => SetProperty(ref _colorDisplayName, value);
|
||||
}
|
||||
|
||||
private string _resourceKey;
|
||||
private string _resourceKey = null!;
|
||||
|
||||
public string ResourceKey
|
||||
{
|
||||
@ -163,7 +167,7 @@ public class ColorItemViewModel : ObservableObject
|
||||
set => SetProperty(ref _resourceKey, value);
|
||||
}
|
||||
|
||||
private string _hex;
|
||||
private string _hex = null!;
|
||||
|
||||
public string Hex
|
||||
{
|
||||
@ -190,7 +194,7 @@ public class ColorItemViewModel : ObservableObject
|
||||
|
||||
public class FunctionalColorGroupViewModel : ObservableObject
|
||||
{
|
||||
private string _title;
|
||||
private string _title = null!;
|
||||
public string Title
|
||||
{
|
||||
get => _title;
|
||||
@ -200,21 +204,22 @@ public class FunctionalColorGroupViewModel : ObservableObject
|
||||
public ObservableCollection<ColorItemViewModel> LightColors { get; set; } = new();
|
||||
public ObservableCollection<ColorItemViewModel> DarkColors { get; set; } = new();
|
||||
|
||||
public FunctionalColorGroupViewModel(string title, IResourceDictionary lightDictionary, IResourceDictionary darkDictionary, IReadOnlyList<Tuple<string, string>> tokens)
|
||||
public FunctionalColorGroupViewModel(string title, IResourceDictionary? lightDictionary, IResourceDictionary? darkDictionary, IReadOnlyList<Tuple<string, string>> tokens)
|
||||
{
|
||||
Title = title;
|
||||
foreach (var token in tokens)
|
||||
{
|
||||
string key = token.Item1;
|
||||
string name = token.Item2;
|
||||
if (lightDictionary.TryGetValue(key, out var lightValue))
|
||||
if (lightDictionary?.TryGetValue(key, out var lightValue) ?? false)
|
||||
{
|
||||
if (lightValue is ISolidColorBrush lightBrush)
|
||||
{
|
||||
LightColors.Add(new ColorItemViewModel(name, lightBrush, key, true, 0));
|
||||
}
|
||||
}
|
||||
if (darkDictionary.TryGetValue(key, out var darkValue))
|
||||
|
||||
if (darkDictionary?.TryGetValue(key, out var darkValue) ?? false)
|
||||
{
|
||||
if (darkValue is ISolidColorBrush darkBrush)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user