fix: fix timeline not able to react to theme change.

This commit is contained in:
rabbitism
2023-04-24 23:40:55 +08:00
parent a19bbe118f
commit 0d59b6cd3e
5 changed files with 44 additions and 13 deletions

View File

@@ -48,21 +48,16 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Top" VerticalAlignment="Top"
Classes="start" Classes="start"
Fill="LightGray" /> Fill="{DynamicResource TimelineLineBrush}" />
<Panel Grid.Row="1"> <Panel Grid.Row="1">
<Ellipse <Ellipse
Name="PART_Indicator"
Width="8" Width="8"
Height="8" Height="8"
Margin="2" Margin="2"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Top"> VerticalAlignment="Top"
<Ellipse.Fill> Fill="{DynamicResource DefaultTimelineIconForeground}" />
<MultiBinding Converter="{StaticResource ForegroundConverter}">
<Binding Path="ItemType" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="IconForeground" RelativeSource="{RelativeSource TemplatedParent}" />
</MultiBinding>
</Ellipse.Fill>
</Ellipse>
</Panel> </Panel>
<Rectangle <Rectangle
Grid.Row="2" Grid.Row="2"
@@ -71,7 +66,7 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
Classes="end" Classes="end"
Fill="LightGray" /> Fill="{DynamicResource TimelineLineBrush}" />
</Grid> </Grid>
<Rectangle <Rectangle
Grid.Row="2" Grid.Row="2"
@@ -80,7 +75,7 @@
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
Classes="end" Classes="end"
Fill="LightGray" /> Fill="{DynamicResource TimelineLineBrush}" />
<ContentPresenter <ContentPresenter
Grid.Row="0" Grid.Row="0"
Grid.Column="1" Grid.Column="1"
@@ -112,5 +107,23 @@
<Style Selector="^:last /template/ Rectangle.end"> <Style Selector="^:last /template/ Rectangle.end">
<Setter Property="Rectangle.Fill" Value="Transparent" /> <Setter Property="Rectangle.Fill" Value="Transparent" />
</Style> </Style>
<Style Selector="^:none /template/ Ellipse#PART_Indicator">
<Setter Property="Ellipse.Fill" Value="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=u:TimelineItem}, Path=IconForeground}" />
</Style>
<Style Selector="^:not(:none):default /template/ Ellipse#PART_Indicator">
<Setter Property="Ellipse.Fill" Value="{DynamicResource DefaultTimelineIconForeground}" />
</Style>
<Style Selector="^:not(:none):ongoing /template/ Ellipse#PART_Indicator">
<Setter Property="Ellipse.Fill" Value="{DynamicResource OngoingTimelineIconForeground}" />
</Style>
<Style Selector="^:not(:none):success /template/ Ellipse#PART_Indicator">
<Setter Property="Ellipse.Fill" Value="{DynamicResource SuccessTimelineIconForeground}" />
</Style>
<Style Selector="^:not(:none):warning /template/ Ellipse#PART_Indicator">
<Setter Property="Ellipse.Fill" Value="{DynamicResource WarningTimelineIconForeground}" />
</Style>
<Style Selector="^:not(:none):error /template/ Ellipse#PART_Indicator">
<Setter Property="Ellipse.Fill" Value="{DynamicResource ErrorTimelineIconForeground}" />
</Style>
</ControlTheme> </ControlTheme>
</ResourceDictionary> </ResourceDictionary>

View File

@@ -0,0 +1,9 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<!-- Add Resources Here -->
<SolidColorBrush x:Key="DefaultTimelineIconForeground" Opacity="0.2" Color="White" />
<SolidColorBrush x:Key="OngoingTimelineIconForeground" Color="#FF54A9FF" />
<SolidColorBrush x:Key="SuccessTimelineIconForeground" Color="#FF5DC264" />
<SolidColorBrush x:Key="WarningTimelineIconForeground" Color="#FFFFAE43" />
<SolidColorBrush x:Key="ErrorTimelineIconForeground" Color="#FFFC725A" />
<SolidColorBrush x:Key="TimelineLineBrush" Opacity="0.2" Color="White" />
</ResourceDictionary>

View File

@@ -5,5 +5,6 @@
<MergeResourceInclude Source="Banner.axaml" /> <MergeResourceInclude Source="Banner.axaml" />
<MergeResourceInclude Source="Divider.axaml" /> <MergeResourceInclude Source="Divider.axaml" />
<MergeResourceInclude Source="IPv4Box.axaml" /> <MergeResourceInclude Source="IPv4Box.axaml" />
<MergeResourceInclude Source="Timeline.axaml" />
</ResourceDictionary.MergedDictionaries> </ResourceDictionary.MergedDictionaries>
</ResourceDictionary> </ResourceDictionary>

View File

@@ -5,4 +5,5 @@
<SolidColorBrush x:Key="SuccessTimelineIconForeground" Color="#FF3BB346" /> <SolidColorBrush x:Key="SuccessTimelineIconForeground" Color="#FF3BB346" />
<SolidColorBrush x:Key="WarningTimelineIconForeground" Color="#FFFC8800" /> <SolidColorBrush x:Key="WarningTimelineIconForeground" Color="#FFFC8800" />
<SolidColorBrush x:Key="ErrorTimelineIconForeground" Color="#FFF93920" /> <SolidColorBrush x:Key="ErrorTimelineIconForeground" Color="#FFF93920" />
<SolidColorBrush x:Key="TimelineLineBrush" Opacity="0.13" Color="#FF2E3238" />
</ResourceDictionary> </ResourceDictionary>

View File

@@ -8,7 +8,7 @@ using Avalonia.Media;
namespace Ursa.Controls; namespace Ursa.Controls;
[PseudoClasses(PC_First, PC_Last, PC_Default, PC_Ongoing, PC_Success, PC_Warning, PC_Error)] [PseudoClasses(PC_First, PC_Last, PC_Default, PC_Ongoing, PC_Success, PC_Warning, PC_Error, PC_None)]
public class TimelineItem: ContentControl public class TimelineItem: ContentControl
{ {
private const string PC_First = ":first"; private const string PC_First = ":first";
@@ -18,6 +18,7 @@ public class TimelineItem: ContentControl
private const string PC_Success = ":success"; private const string PC_Success = ":success";
private const string PC_Warning = ":warning"; private const string PC_Warning = ":warning";
private const string PC_Error = ":error"; private const string PC_Error = ":error";
private const string PC_None = ":none";
private static readonly IReadOnlyDictionary<TimelineItemType, string> _itemTypeMapping = new Dictionary<TimelineItemType, string> private static readonly IReadOnlyDictionary<TimelineItemType, string> _itemTypeMapping = new Dictionary<TimelineItemType, string>
{ {
@@ -81,6 +82,7 @@ public class TimelineItem: ContentControl
static TimelineItem() static TimelineItem()
{ {
ItemTypeProperty.Changed.AddClassHandler<TimelineItem>((o, e) => { o.OnItemTypeChanged(e); }); ItemTypeProperty.Changed.AddClassHandler<TimelineItem>((o, e) => { o.OnItemTypeChanged(e); });
IconForegroundProperty.Changed.AddClassHandler<TimelineItem>((o, e) => { o.OnIconForegroundChanged(e); });
} }
private void OnItemTypeChanged(AvaloniaPropertyChangedEventArgs args) private void OnItemTypeChanged(AvaloniaPropertyChangedEventArgs args)
@@ -91,4 +93,9 @@ public class TimelineItem: ContentControl
PseudoClasses.Set(_itemTypeMapping[newValue], true); PseudoClasses.Set(_itemTypeMapping[newValue], true);
} }
private void OnIconForegroundChanged(AvaloniaPropertyChangedEventArgs args)
{
IBrush? newValue = args.GetOldValue<IBrush?>();
PseudoClasses.Set(PC_None, newValue is null);
}
} }