Merge pull request #303 from irihitech/rc/297-refresh-container
Implement RefreshContainer
This commit is contained in:
commit
833ccadb58
@ -4,12 +4,24 @@
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:pages="clr-namespace:Semi.Avalonia.Demo.Pages"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:DataType="pages:RefreshContainerDemoViewModel"
|
||||
x:CompileBindings="True"
|
||||
mc:Ignorable="d">
|
||||
<StackPanel HorizontalAlignment="Left" Spacing="20">
|
||||
<RefreshContainer Name="container">
|
||||
<TextBlock Text="Content" />
|
||||
<DockPanel HorizontalAlignment="Stretch" VerticalAlignment="Top">
|
||||
<Label DockPanel.Dock="Top">A control that supports pull to refresh</Label>
|
||||
<RefreshContainer Name="Refresh"
|
||||
DockPanel.Dock="Bottom"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
PullDirection="TopToBottom"
|
||||
RefreshRequested="RefreshContainerPage_RefreshRequested"
|
||||
Margin="5">
|
||||
<ListBox HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Top"
|
||||
ItemsSource="{Binding Items}" />
|
||||
</RefreshContainer>
|
||||
</StackPanel>
|
||||
</DockPanel>
|
||||
</UserControl>
|
||||
|
@ -1,14 +1,46 @@
|
||||
using Avalonia;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.Markup.Xaml;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
|
||||
namespace Semi.Avalonia.Demo.Pages;
|
||||
|
||||
public partial class RefreshContainerDemo : UserControl
|
||||
{
|
||||
private RefreshContainerDemoViewModel _viewModel;
|
||||
|
||||
public RefreshContainerDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
_viewModel = new RefreshContainerDemoViewModel();
|
||||
|
||||
DataContext = _viewModel;
|
||||
}
|
||||
|
||||
private async void RefreshContainerPage_RefreshRequested(object? sender, RefreshRequestedEventArgs e)
|
||||
{
|
||||
var deferral = e.GetDeferral();
|
||||
|
||||
await _viewModel.AddToTop();
|
||||
|
||||
deferral.Complete();
|
||||
}
|
||||
}
|
||||
|
||||
public class RefreshContainerDemoViewModel : ObservableObject
|
||||
{
|
||||
public ObservableCollection<string> Items { get; }
|
||||
|
||||
public RefreshContainerDemoViewModel()
|
||||
{
|
||||
Items = new ObservableCollection<string>(Enumerable.Range(1, 200).Select(i => $"Item {i}"));
|
||||
}
|
||||
|
||||
public async Task AddToTop()
|
||||
{
|
||||
await Task.Delay(1000);
|
||||
Items.Insert(0, $"Item {200 - Items.Count}");
|
||||
}
|
||||
}
|
@ -28,21 +28,27 @@
|
||||
<Setter Property="IsTabStop" Value="False" />
|
||||
<Setter Property="IsHitTestVisible" Value="False" />
|
||||
<Setter Property="Height" Value="100" />
|
||||
<Setter Property="Background" Value="{DynamicResource RefreshContainerIconBackground}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource RefreshContainerIconForeground}" />
|
||||
<Setter Property="Background" Value="{DynamicResource RefreshVisualizerIconBackground}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource RefreshVisualizerIconForeground}" />
|
||||
<Setter Property="Content">
|
||||
<Template>
|
||||
<Arc
|
||||
Name="PART_Icon"
|
||||
Width="{DynamicResource RefreshVisualizerIconSize}"
|
||||
Height="{DynamicResource RefreshVisualizerIconSize}"
|
||||
StartAngle="0"
|
||||
Stroke="{DynamicResource RefreshVisualizerIconForeground}"
|
||||
StrokeThickness="3"
|
||||
StrokeLineCap="Round"
|
||||
SweepAngle="270" />
|
||||
</Template>
|
||||
</Setter>
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate>
|
||||
<Grid
|
||||
Name="PART_Root"
|
||||
MinHeight="80"
|
||||
Background="{TemplateBinding Background}">
|
||||
<Grid.Styles>
|
||||
<Style Selector="PathIcon#PART_Icon">
|
||||
<Setter Property="Data" Value="{DynamicResource RefreshContainerIconGlyph}" />
|
||||
</Style>
|
||||
</Grid.Styles>
|
||||
</Grid>
|
||||
<Grid Name="PART_Root"
|
||||
MinHeight="80"
|
||||
Background="{TemplateBinding Background}" />
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
</ControlTheme>
|
||||
</ResourceDictionary>
|
||||
</ResourceDictionary>
|
@ -1,4 +1,4 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<SolidColorBrush x:Key="RefreshContainerIconForeground" Color="#54A9FF" />
|
||||
<SolidColorBrush x:Key="RefreshContainerIconBackground" Color="Transparent" />
|
||||
<SolidColorBrush x:Key="RefreshVisualizerIconForeground" Color="#54A9FF" />
|
||||
<SolidColorBrush x:Key="RefreshVisualizerIconBackground" Color="Transparent" />
|
||||
</ResourceDictionary>
|
@ -1,4 +1,4 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<SolidColorBrush x:Key="RefreshContainerIconForeground" Color="#0077FA" />
|
||||
<SolidColorBrush x:Key="RefreshContainerIconBackground" Color="Transparent" />
|
||||
<SolidColorBrush x:Key="RefreshVisualizerIconForeground" Color="#0077FA" />
|
||||
<SolidColorBrush x:Key="RefreshVisualizerIconBackground" Color="Transparent" />
|
||||
</ResourceDictionary>
|
@ -1,3 +1,3 @@
|
||||
<ResourceDictionary xmlns="https://github.com/avaloniaui" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
<PathGeometry x:Key="RefreshContainerIconGlyph">M14.2 3.78966C9.66551 2.57466 5.00465 5.26561 3.78964 9.80007C3.12066 12.2967 3.63433 14.8301 4.99177 16.8102C5.46019 17.4935 5.28601 18.4271 4.60273 18.8955C3.91945 19.364 2.98581 19.1898 2.51739 18.5065C0.685557 15.8344 -0.0134454 12.4023 0.891867 9.02361C2.5357 2.88875 8.84157 -0.751945 14.9764 0.891885C21.1113 2.53572 24.752 8.84159 23.1082 14.9765C22.8937 15.7767 22.0712 16.2515 21.271 16.0371C20.4708 15.8227 19.996 15.0002 20.2104 14.2C21.4254 9.66553 18.7344 5.00467 14.2 3.78966Z</PathGeometry>
|
||||
<x:Double x:Key="RefreshVisualizerIconSize">24</x:Double>
|
||||
</ResourceDictionary>
|
Loading…
x
Reference in New Issue
Block a user