22// Licensed under the MIT License.
33
44using Microsoft . UI . Xaml ;
5+ using Microsoft . UI . Xaml . Controls ;
56using Microsoft . UI . Xaml . Input ;
67using Microsoft . UI . Xaml . Media ;
78using Microsoft . UI . Xaml . Media . Imaging ;
89using Microsoft . UI . Xaml . Navigation ;
910using System . Windows . Input ;
1011using Windows . System ;
11- using Microsoft . UI . Xaml . Controls ;
1212
1313namespace Files . App . ViewModels
1414{
@@ -88,10 +88,27 @@ public Stretch AppThemeBackgroundImageFit
8888 public float AppThemeBackgroundImageOpacity
8989 => AppearanceSettingsService . AppThemeBackgroundImageOpacity ;
9090
91- public ImageSource ? AppThemeBackgroundImageSource =>
92- string . IsNullOrEmpty ( AppearanceSettingsService . AppThemeBackgroundImageSource )
93- ? null
94- : new BitmapImage ( new Uri ( AppearanceSettingsService . AppThemeBackgroundImageSource , UriKind . RelativeOrAbsolute ) ) ;
91+ public ImageSource ? AppThemeBackgroundImageSource
92+ {
93+ get
94+ {
95+ if ( string . IsNullOrWhiteSpace ( AppearanceSettingsService . AppThemeBackgroundImageSource ) )
96+ return null ;
97+
98+ if ( ! Uri . TryCreate ( AppearanceSettingsService . AppThemeBackgroundImageSource , UriKind . RelativeOrAbsolute , out Uri ? validUri ) )
99+ return null ;
100+
101+ try
102+ {
103+ return new BitmapImage ( validUri ) ;
104+ }
105+ catch ( Exception )
106+ {
107+ // Catch potential errors
108+ return null ;
109+ }
110+ }
111+ }
95112
96113 public VerticalAlignment AppThemeBackgroundImageVerticalAlignment
97114 => AppearanceSettingsService . AppThemeBackgroundImageVerticalAlignment ;
@@ -104,7 +121,7 @@ public HorizontalAlignment AppThemeBackgroundImageHorizontalAlignment
104121 context . PageType is not ContentPageTypes . Home &&
105122 context . PageType is not ContentPageTypes . ReleaseNotes &&
106123 context . PageType is not ContentPageTypes . Settings ;
107-
124+
108125 public bool ShowStatusBar =>
109126 context . PageType is not ContentPageTypes . Home &&
110127 context . PageType is not ContentPageTypes . ReleaseNotes &&
0 commit comments