Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Dec 21, 2021
1 parent 3529735 commit 03454ad
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 20 deletions.
21 changes: 12 additions & 9 deletions src/ThemeEditor/Converters/ColorViewModelToBrushConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
4 changes: 2 additions & 2 deletions src/ThemeEditor/Preview/TabControlPage.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private void InitializeComponent()
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
Expand All @@ -69,4 +69,4 @@ private class TabItemViewModel
public string? Text { get; set; }
public bool IsEnabled { get; set; } = true;
}
}
}
2 changes: 1 addition & 1 deletion src/ThemeEditor/ViewModels/ThemeEditorViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ public void Detach()

private Window? GetWindow()
{
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
return desktopLifetime.MainWindow;
}
Expand Down

0 comments on commit 03454ad

Please sign in to comment.