You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.8 KiB
51 lines
1.8 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Windows.Media;
|
|
using System.Windows;
|
|
using MultiTerm.Core.Types;
|
|
|
|
namespace MultiTerm.Wpf.CustomControl;
|
|
|
|
internal class Format
|
|
{
|
|
private readonly string? backgroundColorResourceName;
|
|
|
|
public string Name { get; set; }
|
|
public Brush BackgroundBrush { get; set; }
|
|
public FormatType AssociatedFormatType { get; set; }
|
|
public Format(string name, Brush backgroundBrush, FormatType associatedFormatType)
|
|
{
|
|
this.Name = name;
|
|
this.BackgroundBrush = backgroundBrush;
|
|
this.AssociatedFormatType = associatedFormatType;
|
|
}
|
|
public Format(string name, string backgroundColorResourceName, FormatType associatedFormatType)
|
|
{
|
|
this.Name = name;
|
|
this.backgroundColorResourceName = backgroundColorResourceName;
|
|
this.BackgroundBrush = Brushes.White; // set background brush to white
|
|
this.AssociatedFormatType = associatedFormatType;
|
|
}
|
|
public static List<string> GetListOfNames(IEnumerable<Format> formats)
|
|
{
|
|
return formats.Select(item => item.Name).ToList();
|
|
}
|
|
public static void UpdateBackgroundBrushesFromResources(FrameworkElement fwElement, IEnumerable<Format> formats)
|
|
{
|
|
if (fwElement == null) throw new ArgumentNullException(nameof(fwElement));
|
|
|
|
foreach (var format in formats)
|
|
{
|
|
// if resource name not set => skip
|
|
if (format.backgroundColorResourceName == null) continue;
|
|
|
|
// get background brush color from resources
|
|
try
|
|
{
|
|
format.BackgroundBrush = (SolidColorBrush)fwElement.FindResource(format.backgroundColorResourceName);
|
|
}
|
|
catch (Exception) { continue; } // ignore
|
|
}
|
|
}
|
|
}
|
|
|