public override ResourceDictionary GetResourceDictionary() { var dict = new ResourceDictionary { Source = new Uri(GetThemePath(UserSettingStorage.Instance.Theme), UriKind.Absolute) }; Style queryBoxStyle = dict["QueryBoxStyle"] as Style; if (queryBoxStyle != null) { queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.QueryBoxFont))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStyle))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontWeight))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.QueryBoxFontStretch))); } Style resultItemStyle = dict["ItemTitleStyle"] as Style; Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style; Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style; Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style; if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null) { Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(UserSettingStorage.Instance.ResultItemFont)); Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStyle)); Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontWeight)); Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(UserSettingStorage.Instance.ResultItemFontStretch)); Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch }; Array.ForEach(new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p))); } return(dict); }
public HighlightStyle(bool selected) { var resources = ThemeManager.Instance.GetResourceDictionary(); Color = (Brush)(selected ? resources.Contains("ItemSelectedHighlightColor") ? resources["ItemSelectedHighlightColor"] : resources["BaseItemSelectedHighlightColor"] : resources.Contains("ItemHighlightColor") ? resources["ItemHighlightColor"] : resources["BaseItemHighlightColor"]); FontStyle = FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.Instance.ResultHighlightFontStyle); FontWeight = FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.Instance.ResultHighlightFontWeight); FontStretch = FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.Instance.ResultHighlightFontStretch); }
public ResourceDictionary GetResourceDictionary() { var uri = GetThemePath(Settings.Theme); var dict = new ResourceDictionary { Source = new Uri(uri, UriKind.Absolute) }; Style queryBoxStyle = dict["QueryBoxStyle"] as Style; if (queryBoxStyle != null) { queryBoxStyle.Setters.Add(new Setter(TextBox.FontFamilyProperty, new FontFamily(Settings.QueryBoxFont))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.QueryBoxFontStyle))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.QueryBoxFontWeight))); queryBoxStyle.Setters.Add(new Setter(TextBox.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch))); var caretBrushPropertyValue = queryBoxStyle.Setters.OfType <Setter>().Any(x => x.Property.Name == "CaretBrush"); var foregroundPropertyValue = queryBoxStyle.Setters.OfType <Setter>().Where(x => x.Property.Name == "Foreground") .Select(x => x.Value).FirstOrDefault(); if (!caretBrushPropertyValue && foregroundPropertyValue != null) //otherwise BaseQueryBoxStyle will handle styling { queryBoxStyle.Setters.Add(new Setter(TextBox.CaretBrushProperty, foregroundPropertyValue)); } } Style resultItemStyle = dict["ItemTitleStyle"] as Style; Style resultSubItemStyle = dict["ItemSubTitleStyle"] as Style; Style resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style; Style resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style; if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null) { Setter fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(Settings.ResultFont)); Setter fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.ResultFontStyle)); Setter fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.ResultFontWeight)); Setter fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.ResultFontStretch)); Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch }; Array.ForEach(new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p))); } return(dict); }
public ResourceDictionary GetResourceDictionary() { var uri = GetThemePath(Settings.Theme); var dict = new ResourceDictionary { Source = new Uri(uri, UriKind.Absolute) }; var queryBoxStyle = dict["QueryBoxStyle"] as Style; if (queryBoxStyle != null) { queryBoxStyle.Setters.Add(new Setter(Control.FontFamilyProperty, new FontFamily(Settings.QueryBoxFont))); queryBoxStyle.Setters.Add(new Setter(Control.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.QueryBoxFontStyle))); queryBoxStyle.Setters.Add(new Setter(Control.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.QueryBoxFontWeight))); queryBoxStyle.Setters.Add(new Setter(Control.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch))); var caretBrushPropertyValue = queryBoxStyle.Setters.OfType <Setter>().Any(x => x.Property == TextBoxBase.CaretBrushProperty); var foregroundPropertyValue = queryBoxStyle.Setters.OfType <Setter>().FirstOrDefault(x => x.Property == Control.ForegroundProperty)?.Value; if (!caretBrushPropertyValue && foregroundPropertyValue != null) { queryBoxStyle.Setters.Add(new Setter(TextBoxBase.CaretBrushProperty, foregroundPropertyValue)); } } var queryTextSuggestionBoxStyle = new Style(typeof(TextBox), queryBoxStyle); var hasSuggestion = false; if (dict.Contains("QueryTextSuggestionBoxStyle")) { queryTextSuggestionBoxStyle = dict["QueryTextSuggestionBoxStyle"] as Style; hasSuggestion = true; } dict["QueryTextSuggestionBoxStyle"] = queryTextSuggestionBoxStyle; if (queryTextSuggestionBoxStyle != null) { queryTextSuggestionBoxStyle.Setters.Add(new Setter(Control.FontFamilyProperty, new FontFamily(Settings.QueryBoxFont))); queryTextSuggestionBoxStyle.Setters.Add(new Setter(Control.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.QueryBoxFontStyle))); queryTextSuggestionBoxStyle.Setters.Add(new Setter(Control.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.QueryBoxFontWeight))); queryTextSuggestionBoxStyle.Setters.Add(new Setter(Control.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.QueryBoxFontStretch))); } var queryBoxStyleSetters = queryBoxStyle.Setters.OfType <Setter>().ToList(); var queryTextSuggestionBoxStyleSetters = queryTextSuggestionBoxStyle.Setters.OfType <Setter>().ToList(); foreach (var setter in queryBoxStyleSetters) { if (setter.Property == Control.BackgroundProperty) { continue; } if (setter.Property == Control.ForegroundProperty) { continue; } if (queryTextSuggestionBoxStyleSetters.All(x => x.Property != setter.Property)) { queryTextSuggestionBoxStyle.Setters.Add(setter); } } if (!hasSuggestion) { var backgroundBrush = queryBoxStyle.Setters.OfType <Setter>().FirstOrDefault(x => x.Property == Control.BackgroundProperty)?.Value ?? (dict["BaseQuerySuggestionBoxStyle"] as Style).Setters.OfType <Setter>().FirstOrDefault(x => x.Property == Control.BackgroundProperty).Value; queryBoxStyle.Setters.OfType <Setter>().FirstOrDefault(x => x.Property == Control.BackgroundProperty).Value = Brushes.Transparent; if (queryTextSuggestionBoxStyle.Setters.OfType <Setter>().Any(x => x.Property == Control.BackgroundProperty)) { queryTextSuggestionBoxStyle.Setters.OfType <Setter>().First(x => x.Property == Control.BackgroundProperty).Value = backgroundBrush; } else { queryTextSuggestionBoxStyle.Setters.Add(new Setter(Control.BackgroundProperty, backgroundBrush)); } } var resultItemStyle = dict["ItemTitleStyle"] as Style; var resultSubItemStyle = dict["ItemSubTitleStyle"] as Style; var resultItemSelectedStyle = dict["ItemTitleSelectedStyle"] as Style; var resultSubItemSelectedStyle = dict["ItemSubTitleSelectedStyle"] as Style; if (resultItemStyle != null && resultSubItemStyle != null && resultSubItemSelectedStyle != null && resultItemSelectedStyle != null) { var fontFamily = new Setter(TextBlock.FontFamilyProperty, new FontFamily(Settings.ResultFont)); var fontStyle = new Setter(TextBlock.FontStyleProperty, FontHelper.GetFontStyleFromInvariantStringOrNormal(Settings.ResultFontStyle)); var fontWeight = new Setter(TextBlock.FontWeightProperty, FontHelper.GetFontWeightFromInvariantStringOrNormal(Settings.ResultFontWeight)); var fontStretch = new Setter(TextBlock.FontStretchProperty, FontHelper.GetFontStretchFromInvariantStringOrNormal(Settings.ResultFontStretch)); Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch }; Array.ForEach(new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p))); } return(dict); }