private static void ApplyThemeInternal(this FrameworkElement control, Theme? theme, SolidColorBrush accentBrush, SolidColorBrush contrastBrush) { ValidationHelper.NotNull(control, () => control); // Resource dictionaries paths var lightBrushesUri = new Uri("/Elysium;component/Themes/LightBrushes.xaml", UriKind.Relative); var darkBrushesUri = new Uri("/Elysium;component/Themes/DarkBrushes.xaml", UriKind.Relative); // Resource dictionaries var lightBrushesDictionary = new ResourceDictionary { Source = lightBrushesUri }; var darkBrushesDictionary = new ResourceDictionary { Source = darkBrushesUri }; if (theme == Theme.Light) { // Add LightBrushes.xaml, if not included if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != lightBrushesUri)) { control.Resources.MergedDictionaries.Add(lightBrushesDictionary); } // Remove DarkBrushes.xaml, if included var darkColorsDictionaries = control.Resources.MergedDictionaries.Where(dictionary => dictionary.Source == darkBrushesUri).ToList(); foreach (var dictionary in darkColorsDictionaries) { control.Resources.MergedDictionaries.Remove(dictionary); } } if (theme == Theme.Dark) { // Add DarkBrushes.xaml, if not included if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != darkBrushesUri)) { control.Resources.MergedDictionaries.Add(darkBrushesDictionary); } // Remove LightBrushes.xaml, if included var lightColorsDictionaries = control.Resources.MergedDictionaries.Where(dictionary => dictionary.Source == lightBrushesUri).ToList(); foreach (var dictionary in lightColorsDictionaries) { control.Resources.MergedDictionaries.Remove(dictionary); } } // Bug in WPF 4: http://connect.microsoft.com/VisualStudio/feedback/details/555322/global-wpf-styles-are-not-shown-when-using-2-levels-of-references if (control.Resources.Keys.Count == 0) { control.Resources.Add(typeof(Window), new Style(typeof(Window))); } if (accentBrush != null) { var accentBrushFrozen = !accentBrush.IsFrozen && accentBrush.CanFreeze ? accentBrush.GetAsFrozen() : accentBrush; if (control.Resources.Contains("AccentBrush")) { // Set AccentBrush value, if key exist control.Resources["AccentBrush"] = accentBrushFrozen; } else { // Add AccentBrush key and value, if key doesn't exist control.Resources.Add("AccentBrush", accentBrushFrozen); } } if (contrastBrush != null) { var contrastBrushFrozen = !contrastBrush.IsFrozen && contrastBrush.CanFreeze ? contrastBrush.GetAsFrozen() : contrastBrush; if (control.Resources.Contains("ContrastBrush")) { // Set ContrastBrush value, if key exist control.Resources["ContrastBrush"] = contrastBrushFrozen; } else { // Add ContrastBrush key and value, if key doesn't exist control.Resources.Add("ContrastBrush", contrastBrushFrozen); } var semitransparentContrastBrush = contrastBrush.Clone(); semitransparentContrastBrush.Opacity = 1d / 8d; var semitransparentContrastBrushFrozen = !semitransparentContrastBrush.IsFrozen && semitransparentContrastBrush.CanFreeze ? semitransparentContrastBrush.GetAsFrozen() : semitransparentContrastBrush; if (control.Resources.Contains("SemitransparentContrastBrush")) { // Set SemitransparentContrastBrush value, if key exist control.Resources["SemitransparentContrastBrush"] = semitransparentContrastBrushFrozen; } else { // Add SemitransparentContrastBrush key and value, if key doesn't exist control.Resources.Add("SemitransparentContrastBrush", semitransparentContrastBrushFrozen); } } // Add Generic.xaml, if not included var genericDictionaryUri = new Uri("/Elysium;component/Themes/Generic.xaml", UriKind.Relative); if (control.Resources.MergedDictionaries.All(dictionary => dictionary.Source != genericDictionaryUri)) { control.Resources.MergedDictionaries.Add(new ResourceDictionary { Source = genericDictionaryUri }); } OnThemeChanged(); }
/// <summary> /// Constructor! Hurrah! /// </summary> /// <param name="feeditem"></param> public FeedWin(FeedConfigItem feeditem) { Log.Debug("Constructing feedwin. GUID:{0} URL: {1}", feeditem.Guid, feeditem.Url); InitializeComponent(); fci = feeditem; Width = fci.Width; Left = fci.Position.X; Top = fci.Position.Y; //Kick of thread to figure out what sort of plugin to load for this sort of feed. ThreadPool.QueueUserWorkItem(state => GetFeedType(fci)); //Set up the animations for the mouseovers fadein = new ColorAnimation { AutoReverse = false, From = fci.DefaultColor, To = fci.HoverColor, Duration = new Duration(TimeSpan.FromMilliseconds(200)), RepeatBehavior = new RepeatBehavior(1) }; fadeout = new ColorAnimation { AutoReverse = false, To = fci.DefaultColor, From = fci.HoverColor, Duration = new Duration(TimeSpan.FromMilliseconds(200)), RepeatBehavior = new RepeatBehavior(1) }; textbrush = new SolidColorBrush(feeditem.DefaultColor); //Add the right number of textblocks to the form, depending on what the user asked for. for (var ii = 0; ii < fci.DisplayedItems; ii++) { maingrid.RowDefinitions.Add(new RowDefinition()); var textblock = new TextBlock { Style = (Style)FindResource("linkTextStyle"), Name = string.Format("TextBlock{0}", ii + 1), TextTrimming = TextTrimming.CharacterEllipsis, Foreground = textbrush.Clone(), Background = new SolidColorBrush(Color.FromArgb(1, 0, 0, 0)), FontFamily = fci.FontFamily, FontSize = fci.FontSize, FontStyle = fci.FontStyle, FontWeight = fci.FontWeight, Visibility = Visibility.Collapsed }; textblock.SetValue(Grid.ColumnSpanProperty, 2); RegisterName(textblock.Name, textblock); maingrid.Children.Add(textblock); Grid.SetRow(textblock, ii + 1); } maingrid.RowDefinitions.Add(new RowDefinition()); movehandle = new Image(); movehandle.Width = movehandle.Height = 16; movehandle.Name = "movehandle"; movehandle.HorizontalAlignment = HorizontalAlignment.Left; movehandle.Cursor = Cursors.SizeAll; movehandle.Source = new BitmapImage(new Uri("/Feedling;component/Resources/move-icon.png", UriKind.Relative)); movehandle.SetValue(Grid.ColumnSpanProperty, 2); RegisterName(movehandle.Name, movehandle); maingrid.Children.Add(movehandle); movehandle.MouseDown += movehandle_MouseDown; movehandle.Visibility = Visibility.Collapsed; Grid.SetRow(movehandle, maingrid.RowDefinitions.Count); }
/// <summary> /// Reset the <seealso cref="SolidColorBrush"/> to be used for highlighting the current editor line. /// </summary> /// <param name="newValue"></param> private void AdjustCurrentLineBackground(SolidColorBrush newValue) { if (newValue != null) { HighlightCurrentLineBackgroundRenderer oldRenderer = null; // Make sure there is only one of this type of background renderer // Otherwise, we might keep adding and WPF keeps drawing them on top of each other foreach (var item in this.TextArea.TextView.BackgroundRenderers) { if (item != null) { if (item is HighlightCurrentLineBackgroundRenderer) { oldRenderer = item as HighlightCurrentLineBackgroundRenderer; } } } this.TextArea.TextView.BackgroundRenderers.Remove(oldRenderer); this.TextArea.TextView.BackgroundRenderers.Add(new HighlightCurrentLineBackgroundRenderer(this, newValue.Clone())); // Remove reference to old background renderer instance (if any) and construct BracketRenderer from scratch if (this.mBracketRenderer != null) { this.TextArea.TextView.BackgroundRenderers.Remove(this.mBracketRenderer); this.mBracketRenderer = null; } this.mBracketRenderer = new BracketHighlightRenderer(this.TextArea.TextView); this.TextArea.TextView.BackgroundRenderers.Add(this.mBracketRenderer); } }