Skip to content

Commit 869dd4f

Browse files
committed
Added a theme listener, separate light/dark theme error styles, and property that returns the respective theme.
resolves #3545
1 parent d261a24 commit 869dd4f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

Microsoft.Toolkit.Uwp.SampleApp/Controls/XamlCodeEditor.xaml.cs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ public sealed partial class XamlCodeEditor : UserControl
2121
public static readonly DependencyProperty TextProperty =
2222
DependencyProperty.Register(nameof(Text), typeof(string), typeof(XamlCodeEditor), new PropertyMetadata(string.Empty));
2323

24+
private ThemeListener _themeListener = new ThemeListener();
25+
2426
public XamlCodeEditor()
2527
{
2628
this.InitializeComponent();
@@ -40,7 +42,7 @@ public async void ReportError(XamlExceptionRange error)
4042
// Highlight Error Line
4143
XamlCodeRenderer.Decorations.Add(new IModelDeltaDecoration(
4244
range,
43-
new IModelDecorationOptions() { IsWholeLine = true, ClassName = _errorStyle, HoverMessage = new string[] { error.Message }.ToMarkdownString() }));
45+
new IModelDecorationOptions() { IsWholeLine = true, ClassName = ErrorStyle, HoverMessage = new string[] { error.Message }.ToMarkdownString() }));
4446

4547
// Show Glyph Icon
4648
XamlCodeRenderer.Decorations.Add(new IModelDeltaDecoration(
@@ -121,10 +123,13 @@ public string Text
121123

122124
public DateTime TimeSampleEditedLast { get; private set; } = DateTime.MinValue;
123125

124-
private CssLineStyle _errorStyle = new CssLineStyle()
126+
private CssLineStyle _errorStyle_Light = new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0xFF, 0xD6, 0xD6)) };
127+
private CssLineStyle _errorStyle_Dark = new CssLineStyle() { BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0x6E, 0x00, 0x00)) };
128+
129+
private CssLineStyle ErrorStyle
125130
{
126-
BackgroundColor = new SolidColorBrush(Color.FromArgb(0x00, 0xFF, 0xD6, 0xD6))
127-
};
131+
get => _themeListener.CurrentTheme.Equals(ApplicationTheme.Light) ? _errorStyle_Light : _errorStyle_Dark;
132+
}
128133

129134
private CssGlyphStyle _errorIconStyle = new CssGlyphStyle()
130135
{

0 commit comments

Comments
 (0)