Skip to content

Commit

Permalink
Fix white on white text in DataGrid (#65)
Browse files Browse the repository at this point in the history
  • Loading branch information
apman authored Feb 26, 2025
1 parent ff81069 commit e0ad993
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/MacOS.Avalonia.Theme/Controls/DataGrid.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,20 @@
<Setter Property="Background" Value="{DynamicResource TransparentBrush}" />
<Setter Property="Foreground">
<Setter.Value>
<MultiBinding Converter="{StaticResource BooleanToChoiceConverter}">
<MultiBinding Converter="{x:Static BoolConverters.Or}">
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=DataGridRow}" Path="IsSelected"
Converter="{x:Static BoolConverters.Not}" />
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=Window}" Path="IsActive"
Converter="{x:Static BoolConverters.Not}" />
<MultiBinding Converter="{StaticResource BooleanToChoiceConverter}" ConverterParameter="Foreground White">
<MultiBinding Converter="{x:Static BoolConverters.And}">
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=DataGridRow}" Path="IsSelected" />
<MultiBinding Converter="{x:Static BoolConverters.Or}">
<MultiBinding Converter="{StaticResource IsUnsetConverter}">
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=Window}" />
</MultiBinding>
<MultiBinding Converter="{StaticResource IsExplicitlyTrueConverter}">
<Binding RelativeSource="{RelativeSource FindAncestor, AncestorType=Window}" Path="IsActive" />
</MultiBinding>
</MultiBinding>
</MultiBinding>
<Binding Source="{StaticResource ForegroundHighBrush}" />
<Binding Source="{StaticResource DataGridForegroundSelectedBrush}" />
<Binding Source="{StaticResource ForegroundHighBrush}" />
</MultiBinding>
</Setter.Value>
</Setter>
Expand Down
29 changes: 29 additions & 0 deletions src/MacOS.Avalonia.Theme/Converters/IsExplicitlyTrueConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Globalization;
using Avalonia.Data.Converters;

namespace MacOS.Avalonia.Theme.Converters;

/// <summary>
/// Takes a _single_ input and returns a boolean based on whether the input is a boolean and true.
/// </summary>
/// <param name="value">Any property that may or may not exist</param>
/// <returns>True if the input resolves to true, else False</returns>
/// <remarks>
/// This Converter can be used to check for a property when the source may not even exist. It needs to be a
/// MultiValueConverter,
/// because Avalonia will not call a normal converter if the input value is `unset`.
/// Having this converter is useful, because Avalonia's AND and OR converters will return 'unset' if any of the inputs
/// are unset, even when one of the inputs is a boolean and would be sufficient to verify the conjunction!
/// </remarks>
public class IsExplicitlyTrueConverter : IMultiValueConverter
{
public object Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
return values[0] is true;
}

public object ConvertBack(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
29 changes: 29 additions & 0 deletions src/MacOS.Avalonia.Theme/Converters/IsUnsetConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Globalization;
using Avalonia;
using Avalonia.Data.Converters;

namespace MacOS.Avalonia.Theme.Converters;

/// <summary>
/// Takes a _single_ input and returns a boolean if it is unset.
/// </summary>
/// <param name="value">Any property or property source that may or may not exist</param>
/// <returns>True if the input resolves to AvaloniaProperty.UnsetValue, else False</returns>
/// <remarks>
/// This Converter can be used to check for the presence of a control or property. It needs to be a MultiValueConverter,
/// because Avalonia will not call a normal converter if the input value is `unset`.
/// Having this converter is useful, because Avalonia's AND and OR converters will return 'unset' if any of the inputs
/// are unset, even when one of the inputs is a boolean and would be sufficient to verify the conjunction!
/// </remarks>
public class IsUnsetConverter : IMultiValueConverter
{
public object Convert(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
return values[0] == AvaloniaProperty.UnsetValue;
}

public object ConvertBack(IList<object?> values, Type targetType, object? parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
2 changes: 2 additions & 0 deletions src/MacOS.Avalonia.Theme/Converters/_index.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
<converters:CharToMacOsPasswordCharConverter x:Key="CharToMacOsPasswordCharConverter" />
<converters:RevealPasswordToFontSizeConverter x:Key="RevealPasswordToFontSizeConverter" />
<converters:BooleanToChoiceConverter x:Key="BooleanToChoiceConverter" />
<converters:IsUnsetConverter x:Key="IsUnsetConverter" />
<converters:IsExplicitlyTrueConverter x:Key="IsExplicitlyTrueConverter" />
<converters:ClassToChoiceConverter x:Key="ClassToChoiceConverter" />
<converters:ColorToCssFillConverter x:Key="ColorToCssFillConverter" />
<converters:ThicknessToSelectiveThicknessConverter x:Key="ThicknessToSelectiveThicknessConverter" />
Expand Down

0 comments on commit e0ad993

Please sign in to comment.