public ThemeStateViewModel(ThemeState state, ThemePartViewModel parent) { this.state = state; Parent = parent; properties.AddRange(state.Properties.Select(x => new OwnedThemePropertyViewModel(x))); }
public ValueTask WriteAsync(ThemeState state) { var jsonStr = JsonSerializer.Serialize(state); return(_cookieManager.SetCookieAsync( new CookieOptions(COOKIE_KEY, jsonStr, TimeSpan.FromDays(30)) { Path = "/" })); }
static UxThemeWrapper() { // When in high contrast we want to force the WPF theme to be Classic // because that is the only WPF theme that has full fidelity support for the // high contrast color scheme. Prior to Win8 the OS automatically switched // to Classic theme when in high contrast, but Win8 onwards apps that claim // Win8 OS support via the app.manifest will receive the AeroLite as the theme // when in high contrast. The reason being the OS team wants to give high // contrast a face lift starting Win8. However, WPF isnt setup to support this // currently. Thus we fallback to Classic in this situation. _themeState = new ThemeState(!SystemParameters.HighContrast && SafeNativeMethods.IsUxThemeActive(), null, null); }
private static ThemeState EnsureThemeState(bool themeChanged) { ThemeState themeState = _themeState; // capture latest state bool needName = !themeChanged; string themeName, themeColor; bool needUpdate = true; while (needUpdate) { // compute the desired new state ThemeState newState; if (themeChanged) { // when called in response to a ThemeChange, reevaluate // the full state // Please refer to elaborate comment about high // contrast in the static constructor bool isActive = !SystemParameters.HighContrast && SafeNativeMethods.IsUxThemeActive(); if (isActive && (needName || themeState.ThemeName != null)) { // avoid AI -> AU -> AI transition; get theme name now // (see implementation note 3) GetThemeNameAndColor(out themeName, out themeColor); } else { themeName = themeColor = null; } newState = new ThemeState(isActive, themeName, themeColor); } else { // when called outside of ThemeChange, only update if we // need the name of an active theme if (themeState.IsActive && themeState.ThemeName == null) { GetThemeNameAndColor(out themeName, out themeColor); newState = new ThemeState(themeState.IsActive, themeName, themeColor); } else { newState = themeState; needUpdate = false; } } if (needUpdate) { // try to update the state ThemeState currentState = System.Threading.Interlocked.CompareExchange(ref _themeState, newState, themeState); if (currentState == themeState) { // the update worked, we're done themeState = newState; needUpdate = false; } else if (currentState.IsActive == newState.IsActive && (!newState.IsActive || newState.ThemeName == null || currentState.ThemeName != null) ) { // another thread updated the state while we were in this // method, but installed a state that's as good or better // than the one we wanted. Accept the other update. themeState = currentState; needUpdate = false; } else { // another thread updated the state to something different // from what we wanted. This implies the other thread // was responding to a ThemeChange, but it might have been // an older ThemeChange, in which case the state isn't // valid. To be safe, start over as if responding // to a ThemeChange. themeChanged = true; themeState = currentState; } } } return(themeState); }
public void SelectDefaultTheme(ThemeState theme) { DefaultTheme.SelectByPartialText(theme.ToString().Substring(0, 4), true); }
protected override Theme Read(ContentReader input, Theme existingInstance) { if (existingInstance == null) { existingInstance = new Theme(); } else { foreach (var cursor in existingInstance.Cursors) { PlatformHelper.DestroyCursor(cursor.Cursor); } existingInstance.Cursors.Clear(); existingInstance.Fonts.Clear(); existingInstance.Styles.Clear(); existingInstance.Textures.Clear(); } existingInstance.Content = input.ContentManager; // Read cursors. int numberOfCursors = input.ReadInt32(); for (int i = 0; i < numberOfCursors; i++) { var cursor = new ThemeCursor(); cursor.Name = input.ReadString(); cursor.IsDefault = input.ReadBoolean(); cursor.Cursor = LoadCursor(input); existingInstance.Cursors.Add(cursor); } // Read fonts. int numberOfFonts = input.ReadInt32(); for (int i = 0; i < numberOfFonts; i++) { var font = new ThemeFont(); font.Name = input.ReadString(); font.IsDefault = input.ReadBoolean(); font.Font = input.ReadExternalReference <SpriteFont>(); existingInstance.Fonts.Add(font); } // Read textures. int numberOfTextures = input.ReadInt32(); for (int i = 0; i < numberOfTextures; i++) { var texture = new ThemeTexture(); texture.Name = input.ReadString(); texture.IsDefault = input.ReadBoolean(); texture.Texture = input.ReadExternalReference <Texture2D>(); existingInstance.Textures.Add(texture); } // Read styles. int numberOfStyles = input.ReadInt32(); var inheritanceTable = new Dictionary <ThemeStyle, string>(); for (int i = 0; i < numberOfStyles; i++) { var style = new ThemeStyle(); style.Name = input.ReadString(); inheritanceTable.Add(style, input.ReadString()); // Read attributes int numberOfAttributes = input.ReadInt32(); for (int j = 0; j < numberOfAttributes; j++) { var attribute = new ThemeAttribute(); attribute.Name = input.ReadString(); attribute.Value = input.ReadString(); style.Attributes.Add(attribute); } // Read states. int numberOfStates = input.ReadInt32(); for (int j = 0; j < numberOfStates; j++) { var state = new ThemeState(); state.Name = input.ReadString(); state.IsInherited = input.ReadBoolean(); // Read images. int numberOfImages = input.ReadInt32(); for (int k = 0; k < numberOfImages; k++) { var image = new ThemeImage(); image.Name = input.ReadString(); string textureName = input.ReadString(); if (!string.IsNullOrEmpty(textureName)) { ThemeTexture texture; if (existingInstance.Textures.TryGet(textureName, out texture)) { image.Texture = texture; } } image.SourceRectangle = input.ReadRawObject <Rectangle>(); image.Margin = input.ReadRawObject <Vector4F>(); image.HorizontalAlignment = (HorizontalAlignment)input.ReadInt32(); image.VerticalAlignment = (VerticalAlignment)input.ReadInt32(); image.TileMode = (TileMode)input.ReadInt32(); image.Border = input.ReadRawObject <Vector4F>(); image.IsOverlay = input.ReadBoolean(); image.Color = input.ReadColor(); state.Images.Add(image); } bool hasBackground = input.ReadBoolean(); if (hasBackground) { state.Background = input.ReadColor(); } bool hasForeground = input.ReadBoolean(); if (hasForeground) { state.Foreground = input.ReadColor(); } bool hasOpacity = input.ReadBoolean(); if (hasOpacity) { state.Opacity = input.ReadSingle(); } style.States.Add(state); } existingInstance.Styles.Add(style); } // Resolve style inheritance. foreach (var entry in inheritanceTable) { var style = entry.Key; string parentName = entry.Value; if (string.IsNullOrEmpty(parentName)) { continue; } ThemeStyle parent; if (existingInstance.Styles.TryGet(parentName, out parent)) { style.Inherits = parent; } } return(existingInstance); }