feat: Add ProgressButton control and demo.
This commit is contained in:
1 parent
d50c08c629
commit
c48a634220
8 files changed
+526
-20
No files matched your search
@@ -44,6 +44,7 @@
|
||||
[ "ConfettiCannon", "ConfettiCannonDemo", "Brush.Favorite", "", "Interacting" ],
|
||||
[ "Gravatar", "GravatarDemo", "Brush.User", "", "DataDisplay" ],
|
||||
[ "ButtonGroup", "ButtonGroupDemo", "Brush.ButtonGroup", "", "Button" ],
|
||||
[ "ProgressButton", "ProgressButtonDemo", "Brush.ProgressBarStatusBar8", "", "Button" ],
|
||||
[ "Card", "CardDemo", "Brush.ContactCard", "", "DataDisplay" ],
|
||||
[ "ElementGroup", "ElementGroupDemo", "Brush.ButtonGroup", "", "Layout" ],
|
||||
[ "CirclePanel", "CirclePanelDemo", "Brush.ColorWheel", "", "Layout" ],
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
x:Class="HandyControlDemo.UserControl.ProgressButtonDemo">
|
||||
<ScrollViewer>
|
||||
<WrapPanel Margin="16"
|
||||
VerticalAlignment="Center">
|
||||
<StackPanel Margin="16"
|
||||
Spacing="0">
|
||||
<hc:ProgressButton Width="180"
|
||||
Margin="5"
|
||||
Progress="{Binding Progress}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
<hc:ProgressButton Width="180"
|
||||
Margin="5"
|
||||
Theme="{StaticResource ProgressButtonPrimary}"
|
||||
Progress="{Binding Progress}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
<hc:ProgressButton Width="180"
|
||||
Margin="5"
|
||||
Theme="{StaticResource ProgressButtonSuccess}"
|
||||
Progress="{Binding Progress}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
<hc:ProgressButton Width="180"
|
||||
Margin="5"
|
||||
Theme="{StaticResource ProgressButtonInfo}"
|
||||
Progress="{Binding Progress}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
<hc:ProgressButton Width="180"
|
||||
Margin="5"
|
||||
Theme="{StaticResource ProgressButtonWarning}"
|
||||
Progress="{Binding Progress}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
<hc:ProgressButton Width="180"
|
||||
Margin="5"
|
||||
Theme="{StaticResource ProgressButtonDanger}"
|
||||
Progress="{Binding Progress}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
</StackPanel>
|
||||
<StackPanel Margin="16"
|
||||
Spacing="0">
|
||||
<ToggleButton Width="180"
|
||||
Margin="5"
|
||||
Theme="{StaticResource ToggleButtonLoading}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
<ToggleButton Width="180"
|
||||
Margin="5"
|
||||
Theme="{StaticResource ToggleButtonLoadingPrimary}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
<ToggleButton Width="180"
|
||||
Margin="5"
|
||||
Theme="{StaticResource ToggleButtonLoadingSuccess}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
<ToggleButton Width="180"
|
||||
Margin="5"
|
||||
Theme="{StaticResource ToggleButtonLoadingInfo}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
<ToggleButton Width="180"
|
||||
Margin="5"
|
||||
Theme="{StaticResource ToggleButtonLoadingWarning}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
<ToggleButton Width="180"
|
||||
Margin="5"
|
||||
Theme="{StaticResource ToggleButtonLoadingDanger}"
|
||||
IsChecked="{Binding IsUploading, Mode=TwoWay}"
|
||||
Content="{Binding UploadContent}" />
|
||||
</StackPanel>
|
||||
</WrapPanel>
|
||||
</ScrollViewer>
|
||||
</UserControl>
|
||||
+114
@@ -0,0 +1,114 @@
|
||||
using System;
|
||||
using Avalonia;
|
||||
using Avalonia.Threading;
|
||||
using HandyControlDemo.Properties.Langs;
|
||||
|
||||
namespace HandyControlDemo.UserControl;
|
||||
|
||||
public partial class ProgressButtonDemo : Avalonia.Controls.UserControl
|
||||
{
|
||||
private readonly DispatcherTimer _timer;
|
||||
|
||||
private int _progress;
|
||||
private bool _isUploading;
|
||||
|
||||
public static readonly DirectProperty<ProgressButtonDemo, int> ProgressProperty =
|
||||
AvaloniaProperty.RegisterDirect<ProgressButtonDemo, int>(nameof(Progress), o => o.Progress, (o, v) => o.Progress = v);
|
||||
|
||||
public static readonly DirectProperty<ProgressButtonDemo, bool> IsUploadingProperty =
|
||||
AvaloniaProperty.RegisterDirect<ProgressButtonDemo, bool>(nameof(IsUploading), o => o.IsUploading, (o, v) => o.IsUploading = v);
|
||||
|
||||
public static readonly DirectProperty<ProgressButtonDemo, string> UploadContentProperty =
|
||||
AvaloniaProperty.RegisterDirect<ProgressButtonDemo, string>(nameof(UploadContent), o => o.UploadContent);
|
||||
|
||||
public ProgressButtonDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = this;
|
||||
|
||||
_timer = new DispatcherTimer
|
||||
{
|
||||
Interval = TimeSpan.FromMilliseconds(200)
|
||||
};
|
||||
_timer.Tick += Timer_Tick;
|
||||
}
|
||||
|
||||
public int Progress
|
||||
{
|
||||
get => _progress;
|
||||
set
|
||||
{
|
||||
if (_progress == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var oldValue = _progress;
|
||||
_progress = value;
|
||||
RaisePropertyChanged(ProgressProperty, oldValue, value);
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsUploading
|
||||
{
|
||||
get => _isUploading;
|
||||
set
|
||||
{
|
||||
if (_isUploading == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var oldValue = _isUploading;
|
||||
var oldUploadContent = UploadContent;
|
||||
_isUploading = value;
|
||||
RaisePropertyChanged(IsUploadingProperty, oldValue, value);
|
||||
RaisePropertyChanged(UploadContentProperty, oldUploadContent, UploadContent);
|
||||
|
||||
if (_isUploading)
|
||||
{
|
||||
if (!_timer.IsEnabled)
|
||||
{
|
||||
_timer.Start();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_timer.IsEnabled)
|
||||
{
|
||||
_timer.Stop();
|
||||
}
|
||||
|
||||
if (Progress != 0)
|
||||
{
|
||||
Progress = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string UploadContent
|
||||
{
|
||||
get
|
||||
{
|
||||
var values = Lang.UploadStr.Split(';');
|
||||
if (values.Length < 2)
|
||||
{
|
||||
return Lang.UploadStr;
|
||||
}
|
||||
|
||||
return (IsUploading ? values[1] : values[0]).Trim();
|
||||
}
|
||||
}
|
||||
|
||||
private void Timer_Tick(object? sender, EventArgs e)
|
||||
{
|
||||
Progress++;
|
||||
if (Progress >= 100)
|
||||
{
|
||||
Progress = 0;
|
||||
IsUploading = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user