public async Task <bool> TryLoadSkinAsync(AppSkin skin) { try { StorageFile file; if (skin.IsFromOptionalPackage) { if (OptionalPackageSkinFolder != null) { file = await OptionalPackageSkinFolder.GetFileAsync(skin.Path); } else { return(false); } } else { file = await SkinFolder.GetFileAsync(skin.Path); } CurrentSkinResources = await FileIO.ReadTextAsync(file); var xaml = XamlReader.Load(CurrentSkinResources) as ResourceDictionary; xaml.Add("CustomSkinID", skin.Key); App.Current.Resources.MergedDictionaries.Add(xaml); return(true); } catch (Exception) { return(false); } }
public bool RemoveSkin(AppSkin skin) { try { App.Current.Resources.MergedDictionaries.Remove(App.Current.Resources.MergedDictionaries.FirstOrDefault(x => x.TryGetValue("CustomSkinID", out var key) && (key as string) == skin.Key)); return(true); } catch (Exception) { return(false); } }
public async void UpdateSkin(AppSkin OldSkin, AppSkin NewSkin) { if (OldSkin.Path != null) { RemoveSkin(OldSkin); } if (NewSkin.Path != null) { await TryLoadSkinAsync(NewSkin); } }