feat: add demo.
This commit is contained in:
19
demo/Ursa.Demo/Pages/PopConfirmDemo.axaml
Normal file
19
demo/Ursa.Demo/Pages/PopConfirmDemo.axaml
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
<UserControl xmlns="https://github.com/avaloniaui"
|
||||||
|
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:u="https://irihi.tech/ursa"
|
||||||
|
xmlns:viewModels="clr-namespace:Ursa.Demo.ViewModels"
|
||||||
|
mc:Ignorable="d" d:DesignWidth="800"
|
||||||
|
d:DesignHeight="450"
|
||||||
|
x:DataType="viewModels:PopConfirmDemoViewModel"
|
||||||
|
x:Class="Ursa.Demo.Pages.PopConfirmDemo">
|
||||||
|
<StackPanel HorizontalAlignment="Left">
|
||||||
|
<u:PopConfirm PopupHeader="Header" PopupContent="Content"
|
||||||
|
ConfirmCommand="{Binding Path=ConfirmCommand}"
|
||||||
|
CancelCommand="{Binding Path=CancelCommand}"
|
||||||
|
>
|
||||||
|
<Button Content="Hello World"></Button>
|
||||||
|
</u:PopConfirm>
|
||||||
|
</StackPanel>
|
||||||
|
</UserControl>
|
||||||
25
demo/Ursa.Demo/Pages/PopConfirmDemo.axaml.cs
Normal file
25
demo/Ursa.Demo/Pages/PopConfirmDemo.axaml.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Markup.Xaml;
|
||||||
|
using Ursa.Controls;
|
||||||
|
using Ursa.Demo.ViewModels;
|
||||||
|
|
||||||
|
namespace Ursa.Demo.Pages;
|
||||||
|
|
||||||
|
public partial class PopConfirmDemo : UserControl
|
||||||
|
{
|
||||||
|
public PopConfirmDemo()
|
||||||
|
{
|
||||||
|
InitializeComponent();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||||
|
{
|
||||||
|
base.OnAttachedToVisualTree(e);
|
||||||
|
if (this.DataContext is not PopConfirmDemoViewModel vm) return;
|
||||||
|
var manager = WindowToastManager.TryGetToastManager(TopLevel.GetTopLevel(this), out var m)
|
||||||
|
? m
|
||||||
|
: new WindowToastManager(TopLevel.GetTopLevel(this));
|
||||||
|
vm.ToastManager = manager;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -69,6 +69,7 @@ public partial class MainViewViewModel : ViewModelBase
|
|||||||
MenuKeys.MenuKeyNumPad => new NumPadDemoViewModel(),
|
MenuKeys.MenuKeyNumPad => new NumPadDemoViewModel(),
|
||||||
MenuKeys.MenuKeyPagination => new PaginationDemoViewModel(),
|
MenuKeys.MenuKeyPagination => new PaginationDemoViewModel(),
|
||||||
MenuKeys.MenuKeyPinCode => new PinCodeDemoViewModel(),
|
MenuKeys.MenuKeyPinCode => new PinCodeDemoViewModel(),
|
||||||
|
MenuKeys.MenuKeyPopConfirm => new PopConfirmDemoViewModel(),
|
||||||
MenuKeys.MenuKeyRangeSlider => new RangeSliderDemoViewModel(),
|
MenuKeys.MenuKeyRangeSlider => new RangeSliderDemoViewModel(),
|
||||||
MenuKeys.MenuKeyRating => new RatingDemoViewModel(),
|
MenuKeys.MenuKeyRating => new RatingDemoViewModel(),
|
||||||
MenuKeys.MenuKeyScrollToButton => new ScrollToButtonDemoViewModel(),
|
MenuKeys.MenuKeyScrollToButton => new ScrollToButtonDemoViewModel(),
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ public class MenuViewModel : ViewModelBase
|
|||||||
new() { MenuHeader = "Loading", Key = MenuKeys.MenuKeyLoading, Status = "Updated" },
|
new() { MenuHeader = "Loading", Key = MenuKeys.MenuKeyLoading, Status = "Updated" },
|
||||||
new() { MenuHeader = "Message Box", Key = MenuKeys.MenuKeyMessageBox },
|
new() { MenuHeader = "Message Box", Key = MenuKeys.MenuKeyMessageBox },
|
||||||
new() { MenuHeader = "Notification", Key = MenuKeys.MenuKeyNotification },
|
new() { MenuHeader = "Notification", Key = MenuKeys.MenuKeyNotification },
|
||||||
|
new() { MenuHeader = "PopConfirm", Key = MenuKeys.MenuKeyPopConfirm },
|
||||||
new() { MenuHeader = "Toast", Key = MenuKeys.MenuKeyToast },
|
new() { MenuHeader = "Toast", Key = MenuKeys.MenuKeyToast },
|
||||||
new() { MenuHeader = "Skeleton", Key = MenuKeys.MenuKeySkeleton },
|
new() { MenuHeader = "Skeleton", Key = MenuKeys.MenuKeySkeleton },
|
||||||
}
|
}
|
||||||
@@ -135,6 +136,7 @@ public static class MenuKeys
|
|||||||
public const string MenuKeyNumPad = "NumPad";
|
public const string MenuKeyNumPad = "NumPad";
|
||||||
public const string MenuKeyPagination = "Pagination";
|
public const string MenuKeyPagination = "Pagination";
|
||||||
public const string MenuKeyPinCode = "PinCode";
|
public const string MenuKeyPinCode = "PinCode";
|
||||||
|
public const string MenuKeyPopConfirm = "PopConfirm";
|
||||||
public const string MenuKeyRangeSlider = "RangeSlider";
|
public const string MenuKeyRangeSlider = "RangeSlider";
|
||||||
public const string MenuKeyRating = "Rating";
|
public const string MenuKeyRating = "Rating";
|
||||||
public const string MenuKeyScrollToButton = "ScrollToButton";
|
public const string MenuKeyScrollToButton = "ScrollToButton";
|
||||||
|
|||||||
31
demo/Ursa.Demo/ViewModels/PopConfirmDemoViewModel.cs
Normal file
31
demo/Ursa.Demo/ViewModels/PopConfirmDemoViewModel.cs
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
using System.Windows.Input;
|
||||||
|
using Avalonia.Controls.Notifications;
|
||||||
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
|
using CommunityToolkit.Mvvm.Input;
|
||||||
|
using Ursa.Controls;
|
||||||
|
|
||||||
|
namespace Ursa.Demo.ViewModels;
|
||||||
|
|
||||||
|
public partial class PopConfirmDemoViewModel: ObservableObject
|
||||||
|
{
|
||||||
|
internal WindowToastManager? ToastManager { get; set; }
|
||||||
|
|
||||||
|
public ICommand ConfirmCommand { get; }
|
||||||
|
public ICommand CancelCommand { get; }
|
||||||
|
|
||||||
|
public PopConfirmDemoViewModel()
|
||||||
|
{
|
||||||
|
ConfirmCommand = new RelayCommand(OnConfirm);
|
||||||
|
CancelCommand = new RelayCommand(OnCancel);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnConfirm()
|
||||||
|
{
|
||||||
|
ToastManager?.Show(new Toast("Confirmed"), type: NotificationType.Success, classes: ["Light"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCancel()
|
||||||
|
{
|
||||||
|
ToastManager?.Show(new Toast("Canceled"), type:NotificationType.Error, classes: ["Light"]);
|
||||||
|
}
|
||||||
|
}
|
||||||
26
src/Ursa.Themes.Semi/Controls/PopConfirm.axaml
Normal file
26
src/Ursa.Themes.Semi/Controls/PopConfirm.axaml
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:u="https://irihi.tech/ursa">
|
||||||
|
<!-- Add Resources Here -->
|
||||||
|
<ControlTheme x:Key="{x:Type u:PopConfirm}" TargetType="u:PopConfirm">
|
||||||
|
<Setter Property="Template">
|
||||||
|
<ControlTemplate TargetType="u:PopConfirm">
|
||||||
|
<Panel>
|
||||||
|
<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}"/>
|
||||||
|
<Popup IsOpen="True">
|
||||||
|
<Border Theme="{DynamicResource CardBorder}">
|
||||||
|
<StackPanel>
|
||||||
|
<ContentPresenter Content="{TemplateBinding PopupHeader}" ContentTemplate="{TemplateBinding PopupHeaderTemplate}"/>
|
||||||
|
<ContentPresenter Content="{TemplateBinding PopupContent}" ContentTemplate="{TemplateBinding PopupContentTemplate}"/>
|
||||||
|
<StackPanel Orientation="Horizontal">
|
||||||
|
<Button Content="Confirm" Command="{TemplateBinding ConfirmCommand}" CommandParameter="{TemplateBinding ConfirmCommandParameter}"/>
|
||||||
|
<Button Content="Cancel" Command="{TemplateBinding CancelCommand}" CommandParameter="{TemplateBinding CancelCommandParameter}"/>
|
||||||
|
</StackPanel>
|
||||||
|
</StackPanel>
|
||||||
|
</Border>
|
||||||
|
</Popup>
|
||||||
|
</Panel>
|
||||||
|
</ControlTemplate>
|
||||||
|
</Setter>
|
||||||
|
</ControlTheme>
|
||||||
|
</ResourceDictionary>
|
||||||
@@ -36,26 +36,27 @@
|
|||||||
<ResourceInclude Source="NumPad.axaml" />
|
<ResourceInclude Source="NumPad.axaml" />
|
||||||
<ResourceInclude Source="NumberDisplayer.axaml" />
|
<ResourceInclude Source="NumberDisplayer.axaml" />
|
||||||
<ResourceInclude Source="Pagination.axaml" />
|
<ResourceInclude Source="Pagination.axaml" />
|
||||||
|
<ResourceInclude Source="PathPicker.axaml"/>
|
||||||
|
<ResourceInclude Source="PinCode.axaml" />
|
||||||
|
<ResourceInclude Source="PopConfirm.axaml" />
|
||||||
<ResourceInclude Source="RangeSlider.axaml" />
|
<ResourceInclude Source="RangeSlider.axaml" />
|
||||||
<ResourceInclude Source="Rating.axaml" />
|
<ResourceInclude Source="Rating.axaml" />
|
||||||
<ResourceInclude Source="Resizer.axaml" />
|
<ResourceInclude Source="Resizer.axaml" />
|
||||||
<ResourceInclude Source="ScrollToButton.axaml" />
|
<ResourceInclude Source="ScrollToButton.axaml" />
|
||||||
<ResourceInclude Source="SelectionList.axaml" />
|
<ResourceInclude Source="SelectionList.axaml" />
|
||||||
|
<ResourceInclude Source="Skeleton.axaml" />
|
||||||
|
<ResourceInclude Source="SplashWindow.axaml"/>
|
||||||
<ResourceInclude Source="TagInput.axaml" />
|
<ResourceInclude Source="TagInput.axaml" />
|
||||||
<ResourceInclude Source="ThemeSelector.axaml" />
|
<ResourceInclude Source="ThemeSelector.axaml" />
|
||||||
<ResourceInclude Source="TimePicker.axaml" />
|
<ResourceInclude Source="TimePicker.axaml" />
|
||||||
<ResourceInclude Source="TimeRangePicker.axaml" />
|
<ResourceInclude Source="TimeRangePicker.axaml" />
|
||||||
<ResourceInclude Source="Timeline.axaml" />
|
<ResourceInclude Source="Timeline.axaml" />
|
||||||
<ResourceInclude Source="TreeComboBox.axaml"/>
|
<ResourceInclude Source="TreeComboBox.axaml"/>
|
||||||
<ResourceInclude Source="Skeleton.axaml" />
|
|
||||||
<ResourceInclude Source="TwoTonePathIcon.axaml" />
|
<ResourceInclude Source="TwoTonePathIcon.axaml" />
|
||||||
<ResourceInclude Source="Toast.axaml" />
|
<ResourceInclude Source="Toast.axaml" />
|
||||||
<ResourceInclude Source="ToolBar.axaml" />
|
<ResourceInclude Source="ToolBar.axaml" />
|
||||||
<ResourceInclude Source="TimeBox.axaml"/>
|
<ResourceInclude Source="TimeBox.axaml"/>
|
||||||
<ResourceInclude Source="UrsaView.axaml" />
|
<ResourceInclude Source="UrsaView.axaml" />
|
||||||
<ResourceInclude Source="UrsaWindow.axaml"/>
|
<ResourceInclude Source="UrsaWindow.axaml"/>
|
||||||
<ResourceInclude Source="PinCode.axaml" />
|
|
||||||
<ResourceInclude Source="PathPicker.axaml"/>
|
|
||||||
<ResourceInclude Source="SplashWindow.axaml"/>
|
|
||||||
</ResourceDictionary.MergedDictionaries>
|
</ResourceDictionary.MergedDictionaries>
|
||||||
</ResourceDictionary>
|
</ResourceDictionary>
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ using Avalonia.Controls;
|
|||||||
using Avalonia.Controls.Presenters;
|
using Avalonia.Controls.Presenters;
|
||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Controls.Templates;
|
using Avalonia.Controls.Templates;
|
||||||
|
using Avalonia.LogicalTree;
|
||||||
|
using Irihi.Avalonia.Shared.Helpers;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
@@ -113,13 +115,39 @@ public class PopConfirm: ContentControl
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change)
|
||||||
|
{
|
||||||
|
base.OnPropertyChanged(change);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnContentChanged()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate(e);
|
base.OnApplyTemplate(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IDisposable? _childChangeDisposable;
|
||||||
|
|
||||||
protected override bool RegisterContentPresenter(ContentPresenter presenter)
|
protected override bool RegisterContentPresenter(ContentPresenter presenter)
|
||||||
{
|
{
|
||||||
return base.RegisterContentPresenter(presenter);
|
var result = base.RegisterContentPresenter(presenter);
|
||||||
|
_childChangeDisposable = presenter.GetPropertyChangedObservable(ContentPresenter.ChildProperty).Subscribe(OnChildChanged);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnChildChanged(AvaloniaPropertyChangedEventArgs arg)
|
||||||
|
{
|
||||||
|
if (arg.GetNewValue<Control?>() is null) return;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||||
|
{
|
||||||
|
_childChangeDisposable?.Dispose();
|
||||||
|
base.OnDetachedFromLogicalTree(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user