feat: support type.

This commit is contained in:
rabbitism
2024-01-05 00:27:48 +08:00
parent 907bbf16c9
commit 32833d19dd
4 changed files with 52 additions and 32 deletions

View File

@@ -23,7 +23,7 @@
</selectors:TimelineIconTemplateSelector> </selectors:TimelineIconTemplateSelector>
</ResourceDictionary> </ResourceDictionary>
</UserControl.Resources> </UserControl.Resources>
<StackPanel> <WrapPanel>
<u:Timeline <u:Timeline
Mode="Alternate" Mode="Alternate"
HorizontalAlignment="Left" HorizontalAlignment="Left"
@@ -65,12 +65,22 @@
Content="Step 2" Content="Step 2"
Header="第二步" Header="第二步"
Mode="Right" Mode="Right"
Type="Default" /> Type="Success" />
<u:TimelineItem <u:TimelineItem
Content="Step 3" Content="Step 3"
Header="第三步" Header="第三步"
Mode="Separate" Mode="Separate"
Type="Default" /> Type="Warning" />
<u:TimelineItem
Content="Step 4"
Header="第四步"
Mode="Separate"
Type="Ongoing" />
<u:TimelineItem
Content="Step 5"
Header="第五步"
Mode="Separate"
Type="Error" />
</u:Timeline> </u:Timeline>
</StackPanel> </WrapPanel>
</UserControl> </UserControl>

View File

@@ -47,17 +47,24 @@
Grid.RowSpan="3" Grid.RowSpan="3"
Grid.Column="1" Grid.Column="1"
RowDefinitions="Auto, *"> RowDefinitions="Auto, *">
<ContentPresenter <Panel Grid.Row="0" Name="{x:Static u:TimelineItem.PART_Icon}">
Name="{x:Static u:TimelineItem.PART_Icon}" <ContentPresenter
Grid.Row="0" Margin="8"
Margin="8" HorizontalAlignment="Center"
HorizontalAlignment="Center" VerticalAlignment="Center"
VerticalAlignment="Center" Content="{TemplateBinding Icon}"
Content="{TemplateBinding Icon}" ContentTemplate="{TemplateBinding IconTemplate}" />
ContentTemplate="{TemplateBinding IconTemplate}" /> <Ellipse
Name="PART_DefaultIcon"
Width="12"
Height="12"
Margin="8"
IsVisible="False"
Fill="Gray" />
</Panel>
<Rectangle <Rectangle
Grid.Row="1" Grid.Row="1"
Width="1" Width="2"
HorizontalAlignment="Center" HorizontalAlignment="Center"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
Classes="end" Classes="end"
@@ -102,21 +109,26 @@
</Grid> </Grid>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^:first /template/ Rectangle.start">
<Setter Property="Rectangle.Fill" Value="Transparent" />
</Style>
<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="^:empty-icon /template/ ContentPresenter#PART_Icon"> <Style Selector="^:empty-icon /template/ Ellipse#PART_DefaultIcon">
<Setter Property="Content"> <Setter Property="IsVisible" Value="True"/>
<Template> </Style>
<Ellipse <Style Selector="^:empty-icon[Type=Default] /template/ Ellipse#PART_DefaultIcon">
Width="8" <Setter Property="Fill" Value="{DynamicResource SemiGrey6}"/>
Height="8" </Style>
Fill="Gray" /> <Style Selector="^:empty-icon[Type=Error] /template/ Ellipse#PART_DefaultIcon">
</Template> <Setter Property="Fill" Value="{DynamicResource SemiRed6}"/>
</Setter> </Style>
<Style Selector="^:empty-icon[Type=Ongoing] /template/ Ellipse#PART_DefaultIcon">
<Setter Property="Fill" Value="{DynamicResource SemiBlue6}"/>
</Style>
<Style Selector="^:empty-icon[Type=Success] /template/ Ellipse#PART_DefaultIcon">
<Setter Property="Fill" Value="{DynamicResource SemiGreen6}"/>
</Style>
<Style Selector="^:empty-icon[Type=Warning] /template/ Ellipse#PART_DefaultIcon">
<Setter Property="Fill" Value="{DynamicResource SemiOrange6}"/>
</Style> </Style>
<Style Selector="^:all-left"> <Style Selector="^:all-left">
<Style Selector="^ /template/ ContentPresenter#PART_Header"> <Style Selector="^ /template/ ContentPresenter#PART_Header">

View File

@@ -11,7 +11,7 @@ namespace Ursa.Controls;
[PseudoClasses(PC_First, PC_Last, PC_EmptyIcon)] [PseudoClasses(PC_First, PC_Last, PC_EmptyIcon)]
[TemplatePart(PART_Header, typeof(ContentPresenter))] [TemplatePart(PART_Header, typeof(ContentPresenter))]
[TemplatePart(PART_Icon, typeof(ContentPresenter))] [TemplatePart(PART_Icon, typeof(Panel))]
[TemplatePart(PART_Content, typeof(ContentPresenter))] [TemplatePart(PART_Content, typeof(ContentPresenter))]
[TemplatePart(PART_Time, typeof(TextBlock))] [TemplatePart(PART_Time, typeof(TextBlock))]
[TemplatePart(PART_RootGrid, typeof(Grid))] [TemplatePart(PART_RootGrid, typeof(Grid))]
@@ -30,7 +30,7 @@ public class TimelineItem: HeaderedContentControl
public const string PART_RootGrid = "PART_RootGrid"; public const string PART_RootGrid = "PART_RootGrid";
private ContentPresenter? _headerPresenter; private ContentPresenter? _headerPresenter;
private ContentPresenter? _iconPresenter; private Panel? _iconPresenter;
private ContentPresenter? _contentPresenter; private ContentPresenter? _contentPresenter;
private TextBlock? _timePresenter; private TextBlock? _timePresenter;
private Grid? _rootGrid; private Grid? _rootGrid;
@@ -138,11 +138,11 @@ public class TimelineItem: HeaderedContentControl
protected override void OnApplyTemplate(TemplateAppliedEventArgs e) protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{ {
base.OnApplyTemplate(e); base.OnApplyTemplate(e);
_rootGrid = e.NameScope.Find<Grid>(PART_RootGrid);
_headerPresenter = e.NameScope.Find<ContentPresenter>(PART_Header); _headerPresenter = e.NameScope.Find<ContentPresenter>(PART_Header);
_iconPresenter = e.NameScope.Find<ContentPresenter>(PART_Icon); _iconPresenter = e.NameScope.Find<Panel>(PART_Icon);
_contentPresenter = e.NameScope.Find<ContentPresenter>(PART_Content); _contentPresenter = e.NameScope.Find<ContentPresenter>(PART_Content);
_timePresenter = e.NameScope.Find<TextBlock>(PART_Time); _timePresenter = e.NameScope.Find<TextBlock>(PART_Time);
_rootGrid = e.NameScope.Find<Grid>(PART_RootGrid);
PseudoClasses.Set(PC_EmptyIcon, Icon is null); PseudoClasses.Set(PC_EmptyIcon, Icon is null);
SetMode(Mode); SetMode(Mode);
} }

View File

@@ -63,15 +63,13 @@ public class TimelinePanel: Panel
if (child is TimelineItem t) if (child is TimelineItem t)
{ {
t.SetWidth(left, mid, right); t.SetWidth(left, mid, right);
rect = rect.WithHeight(t.DesiredSize.Height);
t.InvalidateArrange(); t.InvalidateArrange();
//rect = rect.WithHeight(t.DesiredSize.Height); rect = rect.WithHeight(t.DesiredSize.Height);
child.Arrange(rect); child.Arrange(rect);
rect = rect.WithY(rect.Y + t.DesiredSize.Height); rect = rect.WithY(rect.Y + t.DesiredSize.Height);
height+=t.DesiredSize.Height; height+=t.DesiredSize.Height;
} }
} }
//return base.ArrangeOverride(finalSize);
return new Size(left + mid + right, height); return new Size(left + mid + right, height);
} }
} }