feat: Add Dialog styles and demo.
This commit is contained in:
1 parent
cb7e6fbb98
commit
2c0875ebd6
20 files changed
+695
-2
No files matched your search
@@ -42,6 +42,7 @@
|
||||
"group": true,
|
||||
"demoItemList": [
|
||||
[ "ConfettiCannon", "ConfettiCannonDemo", "Brush.Favorite", "", "Interacting" ],
|
||||
[ "Dialog", "DialogDemo", "Brush.Dialog", "", "Feedback" ],
|
||||
[ "Gravatar", "GravatarDemo", "Brush.User", "", "DataDisplay" ],
|
||||
[ "ButtonGroup", "ButtonGroupDemo", "Brush.ButtonGroup", "", "Button" ],
|
||||
[ "ProgressButton", "ProgressButtonDemo", "Brush.ProgressBarStatusBar8", "", "Button" ],
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Interactivity;
|
||||
using HandyControl.Controls;
|
||||
using HandyControlDemo.Data;
|
||||
using HandyControlDemo.UserControl;
|
||||
using HandyControlDemo.ViewModel;
|
||||
|
||||
namespace HandyControlDemo;
|
||||
|
||||
public partial class MainWindow : Window
|
||||
public partial class MainWindow : Avalonia.Controls.Window
|
||||
{
|
||||
public MainWindow() => InitializeComponent();
|
||||
public MainWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
Dialog.SetToken(this, MessageToken.MainWindow);
|
||||
}
|
||||
|
||||
protected override void OnLoaded(RoutedEventArgs e)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<Border x:Class="HandyControlDemo.UserControl.InteractiveDialog"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
CornerRadius="10"
|
||||
Width="400"
|
||||
Height="247"
|
||||
Background="{DynamicResource RegionBrush}">
|
||||
<StackPanel VerticalAlignment="Center"
|
||||
Margin="32"
|
||||
Spacing="32">
|
||||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"
|
||||
Text="{Binding Message}" />
|
||||
<TextBox Text="{Binding Result, Mode=TwoWay}"
|
||||
Theme="{StaticResource TextBoxExtend}" />
|
||||
<Button Width="120"
|
||||
Command="{Binding CloseCommand}"
|
||||
Theme="{StaticResource ButtonPrimary}"
|
||||
HorizontalAlignment="Center"
|
||||
Content="OK" />
|
||||
</StackPanel>
|
||||
</Border>
|
||||
@@ -0,0 +1,14 @@
|
||||
using Avalonia.Controls;
|
||||
using HandyControlDemo.ViewModel;
|
||||
|
||||
namespace HandyControlDemo.UserControl;
|
||||
|
||||
public partial class InteractiveDialog : Border
|
||||
{
|
||||
public InteractiveDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = new InteractiveDialogViewModel();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<Border x:Class="HandyControlDemo.UserControl.TextDialog"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
CornerRadius="10"
|
||||
Width="400"
|
||||
Height="247"
|
||||
Background="{DynamicResource RegionBrush}">
|
||||
<Panel>
|
||||
<TextBlock Theme="{StaticResource TextBlockLargeBold}"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Text="Please wait..." />
|
||||
<Button x:Name="CloseButton"
|
||||
Width="22"
|
||||
Height="22"
|
||||
Theme="{StaticResource ButtonIcon}"
|
||||
Foreground="{DynamicResource PrimaryBrush}"
|
||||
hc:IconElement.Geometry="{StaticResource ErrorGeometry}"
|
||||
Padding="0"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,4,4,0" />
|
||||
</Panel>
|
||||
</Border>
|
||||
@@ -0,0 +1,15 @@
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.VisualTree;
|
||||
using HandyControl.Controls;
|
||||
|
||||
namespace HandyControlDemo.UserControl;
|
||||
|
||||
public partial class TextDialog : Border
|
||||
{
|
||||
public TextDialog()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
CloseButton.Click += (_, _) => this.FindAncestorOfType<Dialog>()?.Close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<Border x:Class="HandyControlDemo.UserControl.TextDialogWithTimer"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
CornerRadius="10"
|
||||
Width="400"
|
||||
Height="247"
|
||||
Background="{DynamicResource RegionBrush}">
|
||||
<Panel>
|
||||
<Viewbox Width="80"
|
||||
Height="80"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center">
|
||||
<TextBlock TextWrapping="Wrap"
|
||||
Theme="{StaticResource TextBlockLargeBold}"
|
||||
Text="Please wait..." />
|
||||
</Viewbox>
|
||||
<Button x:Name="CloseButton"
|
||||
Width="22"
|
||||
Height="22"
|
||||
Foreground="{DynamicResource PrimaryBrush}"
|
||||
hc:IconElement.Geometry="{StaticResource ErrorGeometry}"
|
||||
Padding="0"
|
||||
Theme="{StaticResource ButtonIcon}"
|
||||
HorizontalAlignment="Right"
|
||||
VerticalAlignment="Top"
|
||||
Margin="0,4,4,0" />
|
||||
<hc:CircleProgressBar x:Name="ProgressBarTimer"
|
||||
ShowText="False"
|
||||
Width="120"
|
||||
Height="120"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center" />
|
||||
</Panel>
|
||||
</Border>
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Threading;
|
||||
using Avalonia.VisualTree;
|
||||
using HandyControl.Controls;
|
||||
using HandyControlDemo.ViewModel;
|
||||
|
||||
namespace HandyControlDemo.UserControl;
|
||||
|
||||
public partial class TextDialogWithTimer : Border
|
||||
{
|
||||
public TextDialogWithTimer()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = new InteractiveDialogViewModel();
|
||||
|
||||
var startTime = DateTime.Now;
|
||||
var timer = new DispatcherTimer(DispatcherPriority.ApplicationIdle)
|
||||
{
|
||||
Interval = TimeSpan.FromMilliseconds(50)
|
||||
};
|
||||
|
||||
timer.Tick += (_, _) =>
|
||||
{
|
||||
var elapsed = (DateTime.Now - startTime).TotalMilliseconds;
|
||||
var progress = Math.Min(elapsed / 5000.0 * 100, 100);
|
||||
ProgressBarTimer.Value = progress;
|
||||
|
||||
if (progress >= 100)
|
||||
{
|
||||
timer.Stop();
|
||||
this.FindAncestorOfType<Dialog>()?.Close();
|
||||
}
|
||||
};
|
||||
timer.Start();
|
||||
|
||||
CloseButton.Click += (_, _) =>
|
||||
{
|
||||
timer.Stop();
|
||||
this.FindAncestorOfType<Dialog>()?.Close();
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:vm="clr-namespace:HandyControlDemo.ViewModel"
|
||||
xmlns:sys="clr-namespace:System;assembly=System.Runtime"
|
||||
x:Class="HandyControlDemo.UserControl.DialogDemo"
|
||||
DataContext="{Binding DialogDemo, Source={x:Static vm:ViewModelLocator.Instance}}"
|
||||
Background="{DynamicResource RegionBrush}"
|
||||
MinWidth="500">
|
||||
<hc:DialogContainer>
|
||||
<TransitioningContentControl>
|
||||
<Panel>
|
||||
<StackPanel Margin="32"
|
||||
VerticalAlignment="Center">
|
||||
<Button Content="TextDialog"
|
||||
Command="{Binding ShowTextCommand}" />
|
||||
<Button Margin="0,32,0,0"
|
||||
Content="TextDialog(In control)"
|
||||
Command="{Binding ShowTextCommand}"
|
||||
CommandParameter="{Binding $parent[UserControl]}" />
|
||||
<Button Margin="0,32,0,0"
|
||||
Content="TextDialog with timer"
|
||||
Command="{Binding ShowInteractiveDialogCommand}">
|
||||
<Button.CommandParameter>
|
||||
<sys:Boolean>True</sys:Boolean>
|
||||
</Button.CommandParameter>
|
||||
</Button>
|
||||
<TextBox Margin="0,32,0,0"
|
||||
Text="{Binding DialogResult}"
|
||||
Theme="{StaticResource TextBoxExtend}"
|
||||
Watermark="Please input..." />
|
||||
<Button Margin="0,10,0,0"
|
||||
Content="InteractiveDialog"
|
||||
Command="{Binding ShowInteractiveDialogCommand}">
|
||||
<Button.CommandParameter>
|
||||
<sys:Boolean>False</sys:Boolean>
|
||||
</Button.CommandParameter>
|
||||
</Button>
|
||||
<Button Margin="0,32,0,0"
|
||||
Content="New window"
|
||||
Command="{Binding NewWindowCommand}" />
|
||||
</StackPanel>
|
||||
</Panel>
|
||||
</TransitioningContentControl>
|
||||
</hc:DialogContainer>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,16 @@
|
||||
using HandyControl.Controls;
|
||||
using HandyControlDemo.Data;
|
||||
using HandyControlDemo.ViewModel;
|
||||
|
||||
namespace HandyControlDemo.UserControl;
|
||||
|
||||
public partial class DialogDemo : Avalonia.Controls.UserControl
|
||||
{
|
||||
public DialogDemo()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DataContext = ViewModelLocator.Instance.DialogDemo;
|
||||
Dialog.SetToken(this, MessageToken.DialogContainer);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using HandyControl.Tools.Extension;
|
||||
|
||||
namespace HandyControlDemo.ViewModel;
|
||||
|
||||
public partial class InteractiveDialogViewModel : ObservableObject, IDialogResultable<string>
|
||||
{
|
||||
public Action CloseAction { get; set; }
|
||||
|
||||
[ObservableProperty]
|
||||
private string _result;
|
||||
|
||||
[ObservableProperty]
|
||||
private string _message;
|
||||
|
||||
[RelayCommand]
|
||||
private void Close() => CloseAction?.Invoke();
|
||||
}
|
||||
@@ -0,0 +1,70 @@
|
||||
using System.Threading.Tasks;
|
||||
using Avalonia.Controls;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using CommunityToolkit.Mvvm.Input;
|
||||
using HandyControl.Controls;
|
||||
using HandyControl.Tools.Extension;
|
||||
using HandyControlDemo.Data;
|
||||
using HandyControlDemo.UserControl;
|
||||
using HandyControlDemo.Window;
|
||||
|
||||
namespace HandyControlDemo.ViewModel;
|
||||
|
||||
public partial class DialogDemoViewModel : ObservableObject
|
||||
{
|
||||
[ObservableProperty]
|
||||
private string _dialogResult;
|
||||
|
||||
[RelayCommand]
|
||||
private void ShowText(Control? element)
|
||||
{
|
||||
if (element == null)
|
||||
{
|
||||
Dialog.Show(new TextDialog());
|
||||
}
|
||||
else
|
||||
{
|
||||
Dialog.Show(new TextDialog(), MessageToken.DialogContainer);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private async Task ShowInteractiveDialog(bool withTimer)
|
||||
{
|
||||
if (!withTimer)
|
||||
{
|
||||
DialogResult = await Dialog.Show<InteractiveDialog>()
|
||||
.Initialize<InteractiveDialogViewModel>(vm => vm.Message = DialogResult)
|
||||
.GetResultAsync<string>();
|
||||
}
|
||||
else
|
||||
{
|
||||
await Dialog.Show<TextDialogWithTimer>(MessageToken.MainWindow).GetResultAsync<string>();
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void NewWindow()
|
||||
{
|
||||
var window = new DialogDemoWindow();
|
||||
window.Show();
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void ShowWithToken(string token)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
Dialog.Show(new TextDialog(), token);
|
||||
}
|
||||
}
|
||||
|
||||
[RelayCommand]
|
||||
private void CloseMainWindowDialog(string token)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(token))
|
||||
{
|
||||
Dialog.Close(token);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -21,6 +21,7 @@ public class ViewModelLocator
|
||||
services.AddTransient<MainViewModel>();
|
||||
services.AddTransient<InputElementDemoViewModel>();
|
||||
services.AddTransient<CardDemoViewModel>();
|
||||
services.AddTransient<DialogDemoViewModel>();
|
||||
|
||||
_serviceProvider = services.BuildServiceProvider();
|
||||
}
|
||||
@@ -30,4 +31,6 @@ public class ViewModelLocator
|
||||
public InputElementDemoViewModel InputElementDemo => _serviceProvider.GetService<InputElementDemoViewModel>()!;
|
||||
|
||||
public CardDemoViewModel CardDemo => _serviceProvider.GetService<CardDemoViewModel>()!;
|
||||
|
||||
public DialogDemoViewModel DialogDemo => _serviceProvider.GetService<DialogDemoViewModel>()!;
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<Window x:Class="HandyControlDemo.Window.DialogDemoWindow"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:hc="https://handyorg.github.io/handycontrol"
|
||||
xmlns:vm="clr-namespace:HandyControlDemo.ViewModel"
|
||||
xmlns:data="clr-namespace:HandyControlDemo.Data"
|
||||
x:DataType="vm:DialogDemoViewModel"
|
||||
DataContext="{Binding DialogDemo, Source={x:Static vm:ViewModelLocator.Instance}}"
|
||||
Width="800"
|
||||
Height="500"
|
||||
Background="{DynamicResource SecondaryRegionBrush}">
|
||||
<TransitioningContentControl>
|
||||
<hc:UniformSpacingPanel Margin="32"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Center"
|
||||
Orientation="Vertical"
|
||||
Spacing="10">
|
||||
<Button Content="ShowInCurrentWindow"
|
||||
Command="{Binding ShowWithTokenCommand}"
|
||||
CommandParameter="{Binding $parent[Window].DialogToken}" />
|
||||
<Button Content="ShowInMainWindow"
|
||||
Command="{Binding ShowWithTokenCommand}"
|
||||
CommandParameter="{x:Static data:MessageToken.MainWindow}" />
|
||||
<Button Content="CloseMainWindowDialog"
|
||||
Command="{Binding CloseMainWindowDialogCommand}"
|
||||
CommandParameter="{x:Static data:MessageToken.MainWindow}" />
|
||||
</hc:UniformSpacingPanel>
|
||||
</TransitioningContentControl>
|
||||
</Window>
|
||||
@@ -0,0 +1,19 @@
|
||||
using System;
|
||||
using Avalonia.Controls;
|
||||
using HandyControl.Controls;
|
||||
using HandyControlDemo.Data;
|
||||
|
||||
namespace HandyControlDemo.Window;
|
||||
|
||||
public partial class DialogDemoWindow : Avalonia.Controls.Window
|
||||
{
|
||||
public string DialogToken { get; }
|
||||
|
||||
public DialogDemoWindow()
|
||||
{
|
||||
InitializeComponent();
|
||||
|
||||
DialogToken = $"{MessageToken.DialogDemoWindow}+{DateTime.Now:yyyyMMddHHmmssfff}";
|
||||
Dialog.SetToken(this, DialogToken);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user