Skip to content

Commit

Permalink
Fix warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
wieslawsoltes committed Dec 21, 2021
1 parent 8a4f993 commit 049cdf9
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 22 deletions.
19 changes: 11 additions & 8 deletions samples/AvaloniaDemo/Views/MainView.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ private void InitializeThemes()

themes.SelectionChanged += (_, _) =>
{
Application.Current.Styles[0] = themes.SelectedIndex switch
if (Application.Current is { })
{
0 => App.FluentLight,
1 => App.FluentDark,
2 => App.DefaultLight,
3 => App.DefaultDark,
_ => throw new Exception("Not support theme.")
};
Application.Current.Styles[0] = themes.SelectedIndex switch
{
0 => App.FluentLight,
1 => App.FluentDark,
2 => App.DefaultLight,
3 => App.DefaultDark,
_ => throw new Exception("Not support theme.")
};
}
};
}

Expand All @@ -56,4 +59,4 @@ private void InitializeMenu()
}
};
}
}
}
20 changes: 15 additions & 5 deletions samples/Notepad/ViewModels/MainWindowViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,12 @@ public async void FileOpen()
dlg.Filters.Add(new FileDialogFilter() { Name = "Text document", Extensions = { "txt" } });
dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } });
dlg.AllowMultiple = true;
var result = await dlg.ShowAsync(GetWindow());
var window = GetWindow();
if (window is null)
{
return;
}
var result = await dlg.ShowAsync(window);
if (result is { Length: > 0 })
{
foreach (var path in result)
Expand Down Expand Up @@ -164,7 +169,12 @@ private async Task FileSaveAsImpl(FileViewModel fileViewModel)
dlg.Filters.Add(new FileDialogFilter() { Name = "All", Extensions = { "*" } });
dlg.InitialFileName = fileViewModel.Title;
dlg.DefaultExtension = "txt";
var result = await dlg.ShowAsync(GetWindow());
var window = GetWindow();
if (window is null)
{
return;
}
var result = await dlg.ShowAsync(window);
if (result is { })
{
if (!string.IsNullOrEmpty(result))
Expand All @@ -177,7 +187,7 @@ private async Task FileSaveAsImpl(FileViewModel fileViewModel)

public void FileExit()
{
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
desktopLifetime.Shutdown();
}
Expand Down Expand Up @@ -214,10 +224,10 @@ public void Drop(object? sender, DragEventArgs e)

private Window? GetWindow()
{
if (Application.Current.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
if (Application.Current?.ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktopLifetime)
{
return desktopLifetime.MainWindow;
}
return null;
}
}
}
6 changes: 3 additions & 3 deletions src/Dock.Avalonia/Converters/AlignmentConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class AlignmentConverter : IValueConverter
/// <param name="parameter">A user-defined parameter.</param>
/// <param name="culture">The culture to use.</param>
/// <returns>The converted value.</returns>
public object Convert(object? value, Type targetType, object parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value switch
{
Expand All @@ -51,7 +51,7 @@ public object Convert(object? value, Type targetType, object parameter, CultureI
/// <param name="parameter">A user-defined parameter.</param>
/// <param name="culture">The culture to use.</param>
/// <returns>The converted value.</returns>
public object ConvertBack(object? value, Type targetType, object parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value switch
{
Expand All @@ -67,4 +67,4 @@ public object ConvertBack(object? value, Type targetType, object parameter, Cult
_ => value
};
}
}
}
6 changes: 3 additions & 3 deletions src/Dock.Avalonia/Converters/DockModeConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class DockModeConverter : IValueConverter
/// <param name="parameter">A user-defined parameter.</param>
/// <param name="culture">The culture to use.</param>
/// <returns>The converted value.</returns>
public object Convert(object? value, Type targetType, object parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value switch
{
Expand All @@ -50,7 +50,7 @@ public object Convert(object? value, Type targetType, object parameter, CultureI
/// <param name="parameter">A user-defined parameter.</param>
/// <param name="culture">The culture to use.</param>
/// <returns>The converted value.</returns>
public object ConvertBack(object? value, Type targetType, object parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value switch
{
Expand All @@ -66,4 +66,4 @@ public object ConvertBack(object? value, Type targetType, object parameter, Cult
_ => value
};
}
}
}
6 changes: 3 additions & 3 deletions src/Dock.Avalonia/Converters/OrientationConverter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class OrientationConverter : IValueConverter
/// <param name="parameter">A user-defined parameter.</param>
/// <param name="culture">The culture to use.</param>
/// <returns>The converted value.</returns>
public object Convert(object? value, Type targetType, object parameter, CultureInfo culture)
public object Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value switch
{
Expand All @@ -47,7 +47,7 @@ public object Convert(object? value, Type targetType, object parameter, CultureI
/// <param name="parameter">A user-defined parameter.</param>
/// <param name="culture">The culture to use.</param>
/// <returns>The converted value.</returns>
public object ConvertBack(object? value, Type targetType, object parameter, CultureInfo culture)
public object ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
{
return value switch
{
Expand All @@ -61,4 +61,4 @@ public object ConvertBack(object? value, Type targetType, object parameter, Cult
_ => value
};
}
}
}

0 comments on commit 049cdf9

Please sign in to comment.