From 180d8f092aadfd879dcbccfdd3005b2bf6524846 Mon Sep 17 00:00:00 2001 From: Lauren Ciha Date: Tue, 22 Oct 2024 17:40:48 -0700 Subject: [PATCH] Refactor GetIconByTheme() --- .../ViewModels/PackageViewModel.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs index 870cd06082..875c8d64eb 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/PackageViewModel.cs @@ -11,6 +11,7 @@ using DevHome.Services.WindowsPackageManager.Contracts; using DevHome.SetupFlow.Models; using DevHome.SetupFlow.Services; +using Microsoft.UI.Xaml; using Microsoft.UI.Xaml.Media.Imaging; using Windows.Storage.Streams; using Windows.System; @@ -96,7 +97,7 @@ public PackageViewModel( public IWinGetPackage Package => _package; - public BitmapImage Icon => _themeSelector.IsDarkTheme() ? _packageDarkThemeIcon.Value : _packageLightThemeIcon.Value; + public BitmapImage Icon => GetIconByTheme(); public string Name => _package.Name; @@ -202,14 +203,13 @@ private void ToggleSelection() _screenReaderService.Announce(announcementText); } - public BitmapImage GetLightThemeIcon() + private BitmapImage GetIconByTheme() { - return _package.LightThemeIcon == null ? DefaultLightPackageIconSource : CreateBitmapImage(_package.LightThemeIcon); - } - - public BitmapImage GetDarkThemeIcon() - { - return _package.DarkThemeIcon == null ? DefaultDarkPackageIconSource : CreateBitmapImage(_package.DarkThemeIcon); + return _themeSelector.GetActualTheme() switch + { + ElementTheme.Dark => _package.DarkThemeIcon == null ? DefaultDarkPackageIconSource : CreateBitmapImage(_package.DarkThemeIcon), + _ => _package.LightThemeIcon == null ? DefaultLightPackageIconSource : CreateBitmapImage(_package.LightThemeIcon), + }; } private BitmapImage CreateBitmapImage(IRandomAccessStream stream)