private void com_changeSkin_SelectionChanged(object sender, SelectionChangedEventArgs e) { var cb = sender as ComboBox; var skinModel = cb.SelectedItem as SkinViewModel; var skinViewModel = new SkinViewModel(); skinViewModel.ChangeSkin(skinModel); }
public void ChangeSkin(SkinViewModel skinModel) { if (skinModel == null) { return; } var newSkinRes = Application.LoadComponent(new Uri(skinModel.ResFilePath, UriKind.RelativeOrAbsolute)) as ResourceDictionary; if (newSkinRes == null) { return; } newSkinRes.Source = new Uri(skinModel.ResFilePath, UriKind.RelativeOrAbsolute); var oldSkinRes = Application.Current.Resources.MergedDictionaries.Where(x => SkinResList.Any(y => Path.GetFileName(y.ResFilePath) == Path.GetFileName(x.Source.OriginalString))).SingleOrDefault(); if (oldSkinRes == null) { return; } Application.Current.Resources.MergedDictionaries.Remove(oldSkinRes); Application.Current.Resources.MergedDictionaries.Add(newSkinRes); }