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>
</ResourceDictionary>
</UserControl.Resources>
<StackPanel>
<WrapPanel>
<u:Timeline
Mode="Alternate"
HorizontalAlignment="Left"
@@ -65,12 +65,22 @@
Content="Step 2"
Header="第二步"
Mode="Right"
Type="Default" />
Type="Success" />
<u:TimelineItem
Content="Step 3"
Header="第三步"
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>
</StackPanel>
</WrapPanel>
</UserControl>

View File

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

View File

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

View File

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