feat: add icon selector demo.
This commit is contained in:
32
demo/Ursa.Demo/Converters/TimelineIconConverter.cs
Normal file
32
demo/Ursa.Demo/Converters/TimelineIconConverter.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Avalonia;
|
||||
using Avalonia.Data;
|
||||
using Avalonia.Data.Converters;
|
||||
using Avalonia.Media;
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace Ursa.Demo.Converters;
|
||||
|
||||
public class TimelineIconConverter: IValueConverter
|
||||
{
|
||||
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is TimelineItemType t)
|
||||
{
|
||||
return t switch
|
||||
{
|
||||
TimelineItemType.Success => Brushes.Green,
|
||||
TimelineItemType.Ongoing => Brushes.Blue,
|
||||
TimelineItemType.Error => Brushes.Red,
|
||||
_ => Brushes.Gray
|
||||
};
|
||||
}
|
||||
return AvaloniaProperty.UnsetValue;
|
||||
}
|
||||
|
||||
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
@@ -6,15 +6,29 @@
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:viewModels="clr-namespace:Ursa.Demo.ViewModels"
|
||||
xmlns:selectors="clr-namespace:Ursa.Demo.TemplateSelectors"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:DataType="viewModels:TimelineDemoViewModel"
|
||||
x:CompileBindings="True"
|
||||
mc:Ignorable="d">
|
||||
<UserControl.Resources>
|
||||
<ResourceDictionary>
|
||||
<selectors:TimelineIconTemplateSelector x:Key="IconSelector">
|
||||
<Ellipse x:Key="Default" Width="12" Height="12" Fill="{DynamicResource SemiGray6}"></Ellipse>
|
||||
<Ellipse x:Key="Ongoing" Width="12" Height="12" Fill="{DynamicResource SemiBlue6}"></Ellipse>
|
||||
<Ellipse x:Key="Success" Width="12" Height="12" Fill="{DynamicResource SemiGreen6}"></Ellipse>
|
||||
<Ellipse x:Key="Warning" Width="12" Height="12" Fill="{DynamicResource SemiOrange6}"></Ellipse>
|
||||
<Ellipse x:Key="Error" Width="12" Height="12" Fill="{DynamicResource SemiRed6}"></Ellipse>
|
||||
</selectors:TimelineIconTemplateSelector>
|
||||
</ResourceDictionary>
|
||||
</UserControl.Resources>
|
||||
<StackPanel>
|
||||
<u:Timeline ItemsSource="{Binding Items}"
|
||||
HeaderMemberBinding="{ReflectionBinding Header}"
|
||||
DescriptionMemberBinding="{ReflectionBinding Description}"
|
||||
IconMemberBinding="{ReflectionBinding ItemType}"
|
||||
IconTemplate="{StaticResource IconSelector}"
|
||||
>
|
||||
</u:Timeline>
|
||||
<u:Timeline>
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Shapes;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Media;
|
||||
using Ursa.Controls;
|
||||
|
||||
namespace Ursa.Demo.TemplateSelectors;
|
||||
|
||||
public class TimelineIconTemplateSelector: ResourceDictionary, IDataTemplate
|
||||
{
|
||||
|
||||
public Control? Build(object? param)
|
||||
{
|
||||
if (param is TimelineItemType t)
|
||||
{
|
||||
string s = t.ToString();
|
||||
if (ContainsKey(s))
|
||||
{
|
||||
object? o = this[s];
|
||||
if (o is Control c) return c;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public bool Match(object? data)
|
||||
{
|
||||
return data is TimelineItemType;
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,7 @@ public class TimelineDemoViewModel: ViewModelBase
|
||||
TimeFormat = "HH:mm:ss",
|
||||
Description = "Item 2",
|
||||
Header = "发布成功",
|
||||
ItemType = TimelineItemType.Success,
|
||||
ItemType = TimelineItemType.Ongoing,
|
||||
},
|
||||
new()
|
||||
{
|
||||
@@ -30,7 +30,7 @@ public class TimelineDemoViewModel: ViewModelBase
|
||||
TimeFormat = "HH:mm:ss",
|
||||
Description = "Item 3",
|
||||
Header = "审核失败",
|
||||
ItemType = TimelineItemType.Ongoing,
|
||||
ItemType = TimelineItemType.Error,
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@@ -50,14 +50,11 @@
|
||||
Classes="start"
|
||||
Fill="{DynamicResource TimelineLineBrush}" />
|
||||
<Panel Grid.Row="1">
|
||||
<Ellipse
|
||||
Name="PART_Indicator"
|
||||
Width="8"
|
||||
Height="8"
|
||||
Margin="2"
|
||||
<ContentPresenter
|
||||
Content="{TemplateBinding Icon}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Top"
|
||||
Fill="{DynamicResource DefaultTimelineIconForeground}" />
|
||||
VerticalAlignment="Center"
|
||||
ContentTemplate="{TemplateBinding IconTemplate}"/>
|
||||
</Panel>
|
||||
<Rectangle
|
||||
Grid.Row="2"
|
||||
|
||||
Reference in New Issue
Block a user