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:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:u="https://irihi.tech/ursa"
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
xmlns:viewModels="clr-namespace:Ursa.Demo.ViewModels"
|
xmlns:viewModels="clr-namespace:Ursa.Demo.ViewModels"
|
||||||
|
xmlns:selectors="clr-namespace:Ursa.Demo.TemplateSelectors"
|
||||||
d:DesignHeight="450"
|
d:DesignHeight="450"
|
||||||
d:DesignWidth="800"
|
d:DesignWidth="800"
|
||||||
x:DataType="viewModels:TimelineDemoViewModel"
|
x:DataType="viewModels:TimelineDemoViewModel"
|
||||||
x:CompileBindings="True"
|
x:CompileBindings="True"
|
||||||
mc:Ignorable="d">
|
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>
|
<StackPanel>
|
||||||
<u:Timeline ItemsSource="{Binding Items}"
|
<u:Timeline ItemsSource="{Binding Items}"
|
||||||
HeaderMemberBinding="{ReflectionBinding Header}"
|
HeaderMemberBinding="{ReflectionBinding Header}"
|
||||||
DescriptionMemberBinding="{ReflectionBinding Description}"
|
DescriptionMemberBinding="{ReflectionBinding Description}"
|
||||||
|
IconMemberBinding="{ReflectionBinding ItemType}"
|
||||||
|
IconTemplate="{StaticResource IconSelector}"
|
||||||
>
|
>
|
||||||
</u:Timeline>
|
</u:Timeline>
|
||||||
<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",
|
TimeFormat = "HH:mm:ss",
|
||||||
Description = "Item 2",
|
Description = "Item 2",
|
||||||
Header = "发布成功",
|
Header = "发布成功",
|
||||||
ItemType = TimelineItemType.Success,
|
ItemType = TimelineItemType.Ongoing,
|
||||||
},
|
},
|
||||||
new()
|
new()
|
||||||
{
|
{
|
||||||
@@ -30,7 +30,7 @@ public class TimelineDemoViewModel: ViewModelBase
|
|||||||
TimeFormat = "HH:mm:ss",
|
TimeFormat = "HH:mm:ss",
|
||||||
Description = "Item 3",
|
Description = "Item 3",
|
||||||
Header = "审核失败",
|
Header = "审核失败",
|
||||||
ItemType = TimelineItemType.Ongoing,
|
ItemType = TimelineItemType.Error,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,14 +50,11 @@
|
|||||||
Classes="start"
|
Classes="start"
|
||||||
Fill="{DynamicResource TimelineLineBrush}" />
|
Fill="{DynamicResource TimelineLineBrush}" />
|
||||||
<Panel Grid.Row="1">
|
<Panel Grid.Row="1">
|
||||||
<Ellipse
|
<ContentPresenter
|
||||||
Name="PART_Indicator"
|
Content="{TemplateBinding Icon}"
|
||||||
Width="8"
|
|
||||||
Height="8"
|
|
||||||
Margin="2"
|
|
||||||
HorizontalAlignment="Center"
|
HorizontalAlignment="Center"
|
||||||
VerticalAlignment="Top"
|
VerticalAlignment="Center"
|
||||||
Fill="{DynamicResource DefaultTimelineIconForeground}" />
|
ContentTemplate="{TemplateBinding IconTemplate}"/>
|
||||||
</Panel>
|
</Panel>
|
||||||
<Rectangle
|
<Rectangle
|
||||||
Grid.Row="2"
|
Grid.Row="2"
|
||||||
|
|||||||
Reference in New Issue
Block a user