private static bool UpdateAppStyle(AppTheme selectedTheme) { if (selectedTheme == AppTheme.FollowSystem) { selectedTheme = (AppTheme)App.Current.RequestedTheme; } ResourceDictionary theme = selectedTheme switch { AppTheme.Dark => new DarkTheme(), AppTheme.Light => new LightTheme(), _ => throw new InvalidOperationException("Unsupported theme"), }; ICollection <ResourceDictionary> resources = Application.Current.Resources.MergedDictionaries; if (resources.FirstOrDefault()?.GetType() == theme.GetType()) { return(false); } try { resources.Clear(); resources.Add(theme); } catch (Exception ex) { ExceptionService.LogException(ex); } return(true); }
private static object GetDefaultStyleKey(Type viewType, Theme theme, Type elementType) { Type themeType = (theme == null) ? null : theme.GetType(); if (themeType != null) { Type metroThemeType = themeType.Assembly.GetType("Xceed.Wpf.DataGrid.Themes.Metro.MetroTheme"); if ((metroThemeType != null) && metroThemeType.IsAssignableFrom(themeType)) { PropertyInfo trd = metroThemeType.GetProperty("ThemeResourceDictionary"); if (trd != null) { ResourceDictionary rd = ( ResourceDictionary )trd.GetValue(theme, null); if (rd != null) { PropertyInfo ab = rd.GetType().GetProperty("AccentBrush"); if (ab != null) { Brush accentBrush = ( Brush )ab.GetValue(rd, null); return(new ThemeKey(viewType, themeType, elementType, accentBrush)); } } } throw new InvalidOperationException("MetroTheme found but AccentBrush was not found."); } } return(new ThemeKey(viewType, themeType, elementType)); }
"Updating Rg Popup Pages ended");}private static Y s(Z a,Element b,int c, ListView d=null){if(a.TraversedObjects.Contains(b))return Y.Normal();a. TraversedObjects.Add(b);M.q(new string(' ',c*2)+b.GetType().Name);if(b is ListView&&d==null)d=(ListView)b;if(b.GetType().FullName==a.TypeName){if(d!=null &&d!=b){P.u(b.GetType(),a.XamlBuffer.XamlString);var f=v(d);if(f!=null){var g= new Z(a.TypeName,new XamlBuffer("",new List<string>()),a.PropertyList);w(g,f);a. ElementFound=true;return Y.JumpToAncestor(f);}}w(a,b);return Y.Normal();} ResourceDictionary h=null;var i=O.GetMergedResourceDictionary(b,out h);if(i&&h. GetType().FullName==a.TypeName){P.u(h.GetType(),a.XamlBuffer.XamlString);if(b is VisualElement)O.CreateNewMergedResourceDictionary(((VisualElement)b).Resources); else if(b is Application)O.CreateNewMergedResourceDictionary(((Application)b). Resources);var j=v(d??b);if(j!=null){var g=new Z(a.TypeName,new XamlBuffer("", new List<string>()),a.PropertyList);w(g,j);a.ElementFound=true;return Y. JumpToAncestor(j);}}if(b is VisualElement)t(a,b.GetPropertyValue( "NavigationProxy"),c,d);var k=b as IElementController;var l=k!=null?(IEnumerable <Element>)k.LogicalChildren:new Element[0];var m=b is ListView?u((ListView)b):l; foreach(var child in m){if(child==null)continue;var n=s(a,child,c+1,d);if(n.Type ==1&&child!=n.Object)return n;}return Y.Normal();}private static void t(Z a,
public static void DumpResourceDictionary(TextWriter writer, ResourceDictionary rd, string indent = "") { var source = rd.Source; if (source != null) { writer.WriteLine(indent + source + " (" + rd.GetType().FullName + ") # " + rd.GetHashCode()); indent += " "; } foreach (var child in rd.MergedDictionaries) { DumpResourceDictionary(writer, child, indent); } }
/// <summary> /// Creates a validator for a resource. /// </summary> /// <typeparam name="Type">The type of the ype.</typeparam> /// <param name="resourceDictionary">The resource dictionary.</param> /// <param name="resourceKey">The resource key.</param> /// <returns></returns> public static BindingValidator <Type> For <Type>(ResourceDictionary resourceDictionary, object resourceKey) { var method = resourceDictionary.GetType().GetMethod("InitializeComponent"); if (method != null) { method.Invoke(resourceDictionary, null); } var resource = resourceDictionary[resourceKey]; var boundType = new BoundType(typeof(Type)); if (resource is DataTemplate) { return(new BindingValidator <Type>( Bound.DataTemplate(resource as DataTemplate, boundType) )); } if (resource is Style) { return(new BindingValidator <Type>( Bound.Style(resource as Style, boundType) )); } if (resource is GroupStyle) { return(new BindingValidator <Type>( Bound.GroupStyle(resource as GroupStyle, boundType) )); } if (resource is DependencyObject) { return(new BindingValidator <Type>( Bound.DependencyObject(resource as DependencyObject, boundType) )); } throw new NotSupportedException( string.Format( "Resources of type '{0}' are not supported", resource.GetType().FullName ) ); }
public static bool SetAppTheme(AppTheme selectedTheme) { if (selectedTheme == AppTheme.FollowSystem) { selectedTheme = (AppTheme)App.Current.RequestedTheme; } ResourceDictionary theme = selectedTheme switch { AppTheme.Dark => new DarkTheme(), AppTheme.Light => new LightTheme(), _ => throw new InvalidOperationException("Unsupported theme"), }; ICollection <ResourceDictionary> resources = Application.Current.Resources.MergedDictionaries; if (resources == null || resources.FirstOrDefault()?.GetType() == theme.GetType()) { return(false); } resources.Clear(); try { resources.Add(theme); } catch (Exception ex) { MessagingCenter.Send(Application.Current, MessageTypes.ExceptionOccurred, ex); } var statusBarManager = DependencyService.Get <IBarStyleManager>(); statusBarManager.SetStatusBarColor(ResourceManager.StatusBarColor.ToHex()); statusBarManager.SetNavigationBarColor(ResourceManager.NavigationBarColor.ToHex()); MessagingCenter.Send(Application.Current, MessageTypes.ThemeChanged, selectedTheme); return(true); }
public void RemoveResourceDictionary(ResourceDictionary resource) { _logger.Info("Removing resource {0}", resource.GetType().Name); Application.Current.Resources.MergedDictionaries.Remove(resource); }