This commit is contained in:
Wiesław Šoltés 2021-12-21 15:15:09 +01:00
Родитель 3529735712
Коммит 03454ad4f6
4 изменённых файлов: 27 добавлений и 20 удалений

Просмотреть файл

@ -10,26 +10,29 @@ namespace ThemeEditor.Converters;
public class ColorViewModelToBrushConverter : IMultiValueConverter
{
public object Convert(IList<object> values, Type targetType, object parameter, CultureInfo culture)
public object Convert(IList<object?>? values, Type targetType, object? parameter, CultureInfo culture)
{
if (values != null && values.Count() == 4)
{
for (int i = 0; i < 4; i++)
{
if (values[i].GetType() != typeof(byte))
if (values[i]?.GetType() != typeof(byte))
{
return AvaloniaProperty.UnsetValue;
}
}
var color = Color.FromArgb(
(byte)values[0],
(byte)values[1],
(byte)values[2],
(byte)values[3]);
var a = (byte?)values[0];
var r = (byte?)values[1];
var g = (byte?)values[2];
var b = (byte?)values[3];
if (a is { } && r is { } && g is { } && b is { })
{
var color = Color.FromArgb(a.Value, r.Value, g.Value , b.Value);
return new SolidColorBrush(color);
return new SolidColorBrush(color);
}
}
return AvaloniaProperty.UnsetValue;
}
}
}

Просмотреть файл

@ -9,23 +9,27 @@ namespace ThemeEditor.Converters;
public class ThicknessViewModelToThicknessConverter : IMultiValueConverter
{
public object Convert(IList<object> values, Type targetType, object parameter, CultureInfo culture)
public object Convert(IList<object?>? values, Type targetType, object? parameter, CultureInfo culture)
{
if (values != null && values.Count() == 4)
{
for (int i = 0; i < 4; i++)
{
if (values[i].GetType() != typeof(double))
if (values[i]?.GetType() != typeof(double))
{
return AvaloniaProperty.UnsetValue;
}
}
return new Thickness(
(double)values[0],
(double)values[1],
(double)values[2],
(double)values[3]);
var l = (double?)values[0];
var t = (double?)values[1];
var r = (double?)values[2];
var b = (double?)values[3];
if (l is { } && t is { } && r is { } && b is { })
{
return new Thickness(l.Value, t.Value, r.Value, b.Value);
}
}
return AvaloniaProperty.UnsetValue;
}
}
}

Просмотреть файл

@ -47,7 +47,7 @@ public class TabControlPage : UserControl
private IBitmap LoadBitmap(string uri)
{
var assets = AvaloniaLocator.Current.GetService<IAssetLoader>();
return new Bitmap(assets.Open(new Uri(uri)));
return new Bitmap(assets?.Open(new Uri(uri)));
}
private class PageViewModel : ReactiveObject
@ -69,4 +69,4 @@ public class TabControlPage : UserControl
public string? Text { get; set; }
public bool IsEnabled { get; set; } = true;
}
}
}

Просмотреть файл

@ -636,7 +636,7 @@ public class ThemeEditorViewModel : ReactiveObject
private Window? GetWindow()
{
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
return desktopLifetime.MainWindow;
}