feat: add loading.

This commit is contained in:
rabbitism
2023-12-27 17:38:42 +08:00
parent 7890071cae
commit a550513925
5 changed files with 37 additions and 17 deletions

View File

@@ -13,18 +13,19 @@
<vm:SkeletonDemoViewModel /> <vm:SkeletonDemoViewModel />
</Design.DataContext> </Design.DataContext>
<StackPanel> <StackPanel>
<ToggleSwitch Name="s" /> <ToggleSwitch Name="loading" Content="Loading" />
<Grid MinWidth="400" HorizontalAlignment="Left"> <ToggleSwitch Name="active" Content="Active" />
<Grid.ColumnDefinitions> <Grid
<ColumnDefinition Width="auto" /> MinWidth="400"
<ColumnDefinition /> HorizontalAlignment="Left"
</Grid.ColumnDefinitions> ColumnDefinitions="auto,*">
<u:Skeleton <u:Skeleton
Width="100" Width="100"
Height="100" Height="100"
VerticalAlignment="Center" VerticalAlignment="Center"
CornerRadius="2" CornerRadius="2"
IsActive="{Binding #s.IsChecked}"> IsActive="{Binding #active.IsChecked}"
Loading="{Binding #loading.IsChecked}">
<Image RenderOptions.BitmapInterpolationMode="HighQuality" Source="../Assets/Ursa.ico" /> <Image RenderOptions.BitmapInterpolationMode="HighQuality" Source="../Assets/Ursa.ico" />
</u:Skeleton> </u:Skeleton>
<UniformGrid <UniformGrid
@@ -36,20 +37,23 @@
Margin="0,0,200,0" Margin="0,0,200,0"
VerticalAlignment="Top" VerticalAlignment="Top"
CornerRadius="2" CornerRadius="2"
IsActive="{Binding #s.IsChecked}"> IsActive="{Binding #active.IsChecked}"
Loading="{Binding #loading.IsChecked}">
<TextBlock Margin="0,2" Text="是先有鸡还是先有蛋" /> <TextBlock Margin="0,2" Text="是先有鸡还是先有蛋" />
</u:Skeleton> </u:Skeleton>
<u:Skeleton <u:Skeleton
Margin="0,0,100,0" Margin="0,0,100,0"
VerticalAlignment="Center" VerticalAlignment="Center"
CornerRadius="2" CornerRadius="2"
IsActive="{Binding #s.IsChecked}"> IsActive="{Binding #active.IsChecked}"
Loading="{Binding #loading.IsChecked}">
<TextBlock Margin="0,2" Text="什么是工匠精神" /> <TextBlock Margin="0,2" Text="什么是工匠精神" />
</u:Skeleton> </u:Skeleton>
<u:Skeleton <u:Skeleton
VerticalAlignment="Bottom" VerticalAlignment="Bottom"
CornerRadius="2" CornerRadius="2"
IsActive="{Binding #s.IsChecked}"> IsActive="{Binding #active.IsChecked}"
Loading="{Binding #loading.IsChecked}">
<TextBlock Margin="0,2" Text="看山不是山,看水不是水,看山还是山,看水还是水" /> <TextBlock Margin="0,2" Text="看山不是山,看水不是水,看山还是山,看水还是水" />
</u:Skeleton> </u:Skeleton>
</UniformGrid> </UniformGrid>

View File

@@ -26,22 +26,27 @@
ContentTemplate="{TemplateBinding ContentTemplate}" /> ContentTemplate="{TemplateBinding ContentTemplate}" />
<Border <Border
x:Name="PART_Border" x:Name="PART_Border"
IsHitTestVisible="{TemplateBinding IsActive}" Classes.Active="{Binding Path= IsActive, RelativeSource={RelativeSource TemplatedParent}}"
IsVisible="{TemplateBinding IsActive}"> IsHitTestVisible="{TemplateBinding Loading}"
IsVisible="{TemplateBinding Loading}"
>
<Border.Styles> <Border.Styles>
<Style Selector="Border"> <Style Selector="Border">
<Setter Property="Background" Value="{DynamicResource SkeletonDefaultBackground}"></Setter>
</Style>
<Style Selector="Border.Active">
<Style.Animations> <Style.Animations>
<Animation <Animation
FillMode="Both" FillMode="None"
IterationCount="Infinite" IterationCount="Infinite"
Easing="CubicEaseInOut" Easing="CubicEaseInOut"
PlaybackDirection="Alternate" PlaybackDirection="Alternate"
Duration="0:0:1.4"> Duration="0:0:1.4">
<KeyFrame Cue="0%"> <KeyFrame Cue="0%">
<Setter Property="Background" Value="{DynamicResource SkeletonStartAnimationBackground}" /> <Setter Property="Border.Background" Value="{DynamicResource SkeletonStartAnimationBackground}" />
</KeyFrame> </KeyFrame>
<KeyFrame Cue="100%"> <KeyFrame Cue="100%">
<Setter Property="Background" Value="{DynamicResource SkeletonEndAnimationBackground}" /> <Setter Property="Border.Background" Value="{DynamicResource SkeletonEndAnimationBackground}" />
</KeyFrame> </KeyFrame>
</Animation> </Animation>
</Style.Animations> </Style.Animations>

View File

@@ -9,5 +9,6 @@
<GradientStop Offset="1" Color="#FF2E3238" /> <GradientStop Offset="1" Color="#FF2E3238" />
<GradientStop Offset="1" Color="#FF1C1F23" /> <GradientStop Offset="1" Color="#FF1C1F23" />
</LinearGradientBrush> </LinearGradientBrush>
<SolidColorBrush x:Key="SkeletonDefaultBackground" Color="#FF1C1F23"></SolidColorBrush>
<!-- Add Resources Here --> <!-- Add Resources Here -->
</ResourceDictionary> </ResourceDictionary>

View File

@@ -9,5 +9,6 @@
<GradientStop Offset="1" Color="#FFE6E8EA" /> <GradientStop Offset="1" Color="#FFE6E8EA" />
<GradientStop Offset="1" Color="#FFF9F9F9" /> <GradientStop Offset="1" Color="#FFF9F9F9" />
</LinearGradientBrush> </LinearGradientBrush>
<SolidColorBrush x:Key="SkeletonDefaultBackground" Color="#FFF9F9F9"></SolidColorBrush>
<!-- Add Resources Here --> <!-- Add Resources Here -->
</ResourceDictionary> </ResourceDictionary>

View File

@@ -16,5 +16,14 @@ namespace Ursa.Controls
get { return GetValue(IsActiveProperty); } get { return GetValue(IsActiveProperty); }
set { SetValue(IsActiveProperty, value); } set { SetValue(IsActiveProperty, value); }
} }
public static readonly StyledProperty<bool> LoadingProperty =
AvaloniaProperty.Register<Skeleton, bool>(nameof(Loading));
public bool Loading
{
get => GetValue(LoadingProperty);
set => SetValue(LoadingProperty, value);
}
} }
} }