fix: update demo.
This commit is contained in:
@@ -9,10 +9,5 @@
|
||||
x:Class="Ursa.Demo.Dialogs.PlainDialog">
|
||||
<StackPanel>
|
||||
<Calendar SelectedDate="{Binding Date}" ></Calendar>
|
||||
<ComboBox>
|
||||
<ComboBoxItem>A</ComboBoxItem>
|
||||
<ComboBoxItem>B</ComboBoxItem>
|
||||
<ComboBoxItem>C</ComboBoxItem>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,18 +1,99 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
<UserControl
|
||||
x:Class="Ursa.Demo.Pages.DrawerDemo"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:common="clr-namespace:Ursa.Common;assembly=Ursa"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
mc:Ignorable="d" d:DesignWidth="800"
|
||||
xmlns:vm="clr-namespace:Ursa.Demo.ViewModels;assembly=Ursa.Demo"
|
||||
xmlns:u="https://irihi.tech/ursa"
|
||||
xmlns:common="clr-namespace:Ursa.Common;assembly=Ursa"
|
||||
x:DataType="vm:DrawerDemoViewModel"
|
||||
x:CompileBindings="True"
|
||||
xmlns:vm="clr-namespace:Ursa.Demo.ViewModels;assembly=Ursa.Demo"
|
||||
d:DesignHeight="450"
|
||||
x:Class="Ursa.Demo.Pages.DrawerDemo">
|
||||
<StackPanel HorizontalAlignment="Left" >
|
||||
<u:EnumSelector EnumType="{x:Type common:Position}" Value="{Binding SelectedPosition}"></u:EnumSelector>
|
||||
<Button Content="Call Drawer" HorizontalAlignment="Stretch" Command="{Binding OpenDrawerCommand}"></Button>
|
||||
<Button Content="Default Drawer" Command="{Binding OpenDefaultDrawerCommand}"></Button>
|
||||
d:DesignWidth="800"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="vm:DrawerDemoViewModel"
|
||||
mc:Ignorable="d">
|
||||
<Grid ColumnDefinitions="Auto, *">
|
||||
<TabControl Grid.Column="0" Width="300">
|
||||
<TabItem Header="Default">
|
||||
<StackPanel>
|
||||
<u:EnumSelector EnumType="common:Position" Value="{Binding SelectedPosition}" />
|
||||
<ToggleSwitch
|
||||
Content="Global/Local"
|
||||
IsChecked="{Binding IsGlobal}"
|
||||
OffContent="Local"
|
||||
OnContent="Global" />
|
||||
<ToggleSwitch
|
||||
Content="ShowMask"
|
||||
IsChecked="{Binding ShowMask}"
|
||||
OffContent="No"
|
||||
OnContent="Yes" />
|
||||
<ToggleSwitch
|
||||
Content="ClickOnMaskToClose"
|
||||
IsChecked="{Binding CanCloseMaskToClose}"
|
||||
OffContent="No"
|
||||
OnContent="Yes" />
|
||||
<StackPanel Orientation="Horizontal">
|
||||
<TextBlock Text="Buttons" />
|
||||
<u:EnumSelector EnumType="{x:Type u:DialogButton}" Value="{Binding SelectedButton}" />
|
||||
</StackPanel>
|
||||
<Button Command="{Binding ShowDialogCommand}" Content="Show Default Drawer" />
|
||||
<TextBlock>
|
||||
<Run Text="Default Result: " />
|
||||
<Run Text="{Binding DefaultResult}" />
|
||||
</TextBlock>
|
||||
<TextBlock>
|
||||
<Run Text="Dialog Date: " />
|
||||
<Run Text="{Binding Date}" />
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
<TabItem Header="Custom">
|
||||
<StackPanel>
|
||||
<u:EnumSelector EnumType="common:Position" Value="{Binding SelectedPosition}" />
|
||||
<ToggleSwitch
|
||||
Content="Global/Local"
|
||||
IsChecked="{Binding IsGlobal}"
|
||||
OffContent="Local"
|
||||
OnContent="Global" />
|
||||
<ToggleSwitch
|
||||
Content="ClickOnMaskToClose"
|
||||
IsChecked="{Binding CanCloseMaskToClose}"
|
||||
OffContent="No"
|
||||
OnContent="Yes" />
|
||||
<ToggleSwitch
|
||||
Content="ShowMask"
|
||||
IsChecked="{Binding ShowMask}"
|
||||
OffContent="No"
|
||||
OnContent="Yes" />
|
||||
<Button Command="{Binding ShowCustomDialogCommand}" Content="Show Custom Drawer" />
|
||||
<TextBlock>
|
||||
<Run Text="Custom Result: " />
|
||||
<Run Text="{Binding Result}" />
|
||||
</TextBlock>
|
||||
<TextBlock>
|
||||
<Run Text="Dialog Date: " />
|
||||
<Run Text="{Binding Date}" />
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</TabItem>
|
||||
</TabControl>
|
||||
<Grid Grid.Column="1" ClipToBounds="True">
|
||||
<Border
|
||||
BorderBrush="{DynamicResource SemiGrey1}"
|
||||
BorderThickness="1"
|
||||
ClipToBounds="True"
|
||||
CornerRadius="20">
|
||||
<u:OverlayDialogHost HostId="LocalHost">
|
||||
<u:OverlayDialogHost.DialogDataTemplates>
|
||||
<DataTemplate DataType="x:String">
|
||||
<TextBlock
|
||||
Margin="24,24,48,24"
|
||||
Foreground="Red"
|
||||
Text="{Binding Path=.}" />
|
||||
</DataTemplate>
|
||||
</u:OverlayDialogHost.DialogDataTemplates>
|
||||
</u:OverlayDialogHost>
|
||||
</Border>
|
||||
</Grid>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using Avalonia.Controls;
|
||||
@@ -12,33 +14,54 @@ namespace Ursa.Demo.ViewModels;
|
||||
|
||||
public partial class DrawerDemoViewModel: ObservableObject
|
||||
{
|
||||
public ICommand OpenDrawerCommand { get; set; }
|
||||
public ICommand OpenDefaultDrawerCommand { get; set; }
|
||||
public ICommand ShowDialogCommand { get; set; }
|
||||
public ICommand ShowCustomDialogCommand { get; set; }
|
||||
|
||||
[ObservableProperty] private Position _selectedPosition;
|
||||
[ObservableProperty] private DialogButton _selectedButton;
|
||||
[ObservableProperty] private bool _isGlobal;
|
||||
[ObservableProperty] private bool _canCloseMaskToClose;
|
||||
[ObservableProperty] private DialogResult? _defaultResult;
|
||||
[ObservableProperty] private bool _result;
|
||||
[ObservableProperty] private bool _showMask;
|
||||
[ObservableProperty] private DateTime? _date;
|
||||
|
||||
|
||||
public DrawerDemoViewModel()
|
||||
{
|
||||
OpenDrawerCommand = new AsyncRelayCommand(OpenDrawer);
|
||||
OpenDefaultDrawerCommand = new AsyncRelayCommand(OpenDefaultDrawer);
|
||||
SelectedPosition = Position.Right;
|
||||
ShowDialogCommand = new AsyncRelayCommand(ShowDefaultDialog);
|
||||
ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDrawer);
|
||||
}
|
||||
|
||||
private Task OpenDefaultDrawer()
|
||||
private async Task ShowDefaultDialog()
|
||||
{
|
||||
return Drawer.Show<PlainDialog, PlainDialogViewModel, bool>(new PlainDialogViewModel(), new DefaultDrawerOptions()
|
||||
var vm = new PlainDialogViewModel();
|
||||
DefaultResult = await Drawer.Show<PlainDialog, PlainDialogViewModel>(
|
||||
vm,
|
||||
IsGlobal ? null : "LocalHost",
|
||||
new DefaultDrawerOptions()
|
||||
{
|
||||
Buttons = DialogButton.OKCancel,
|
||||
Position = SelectedPosition,
|
||||
Title = "Please select a date",
|
||||
CanClickOnMaskToClose = false,
|
||||
Position = SelectedPosition,
|
||||
Buttons = SelectedButton,
|
||||
CanClickOnMaskToClose = CanCloseMaskToClose,
|
||||
ShowMask = ShowMask,
|
||||
});
|
||||
Date = vm.Date;
|
||||
}
|
||||
|
||||
private async Task OpenDrawer()
|
||||
private async Task ShowCustomDrawer()
|
||||
{
|
||||
await Drawer.ShowCustom<DialogWithAction, DialogWithActionViewModel, bool>(new DialogWithActionViewModel(),
|
||||
new CustomDrawerOptions() { Position = SelectedPosition, MinWidth = 400, MinHeight = 400});
|
||||
var vm = new DialogWithActionViewModel();
|
||||
Result = await Drawer.ShowCustom<DialogWithAction, DialogWithActionViewModel, bool>(
|
||||
vm,
|
||||
IsGlobal ? null : "LocalHost",
|
||||
new CustomDrawerOptions()
|
||||
{
|
||||
Position = SelectedPosition,
|
||||
CanClickOnMaskToClose = CanCloseMaskToClose,
|
||||
ShowMask = ShowMask,
|
||||
});
|
||||
Date = vm.Date;
|
||||
}
|
||||
}
|
||||
@@ -17,7 +17,7 @@
|
||||
BorderThickness="1 0 0 0"
|
||||
IsHitTestVisible="True"
|
||||
Theme="{DynamicResource CardBorder}">
|
||||
<Border ClipToBounds="True" CornerRadius="12 0 0 12">
|
||||
<Border ClipToBounds="True" CornerRadius="{Binding #PART_Root.CornerRadius}">
|
||||
<Grid RowDefinitions="Auto, *">
|
||||
<ContentPresenter
|
||||
Name="PART_ContentPresenter"
|
||||
@@ -80,7 +80,7 @@
|
||||
BorderThickness="1 0 0 0"
|
||||
IsHitTestVisible="True"
|
||||
Theme="{DynamicResource CardBorder}">
|
||||
<Border ClipToBounds="True" CornerRadius="{TemplateBinding CornerRadius}">
|
||||
<Border ClipToBounds="True" CornerRadius="{Binding #PART_Root.CornerRadius}">
|
||||
<Grid RowDefinitions="Auto, *, Auto">
|
||||
<ScrollViewer Grid.Row="1">
|
||||
<ContentPresenter
|
||||
|
||||
@@ -4,6 +4,7 @@ using Avalonia.Controls.Metadata;
|
||||
using Avalonia.Controls.Primitives;
|
||||
using Avalonia.Interactivity;
|
||||
using Ursa.Common;
|
||||
using Ursa.EventArgs;
|
||||
|
||||
namespace Ursa.Controls;
|
||||
|
||||
@@ -123,4 +124,25 @@ public class DefaultDrawerControl: DrawerControlBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override void Close()
|
||||
{
|
||||
if (DataContext is IDialogContext context)
|
||||
{
|
||||
context.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
DialogResult result = Buttons switch
|
||||
{
|
||||
DialogButton.None => DialogResult.None,
|
||||
DialogButton.OK => DialogResult.OK,
|
||||
DialogButton.OKCancel => DialogResult.Cancel,
|
||||
DialogButton.YesNo => DialogResult.No,
|
||||
DialogButton.YesNoCancel => DialogResult.Cancel,
|
||||
_ => DialogResult.None
|
||||
};
|
||||
RaiseEvent(new ResultEventArgs(ClosedEvent, result));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,11 +6,11 @@ namespace Ursa.Controls;
|
||||
|
||||
public static class Drawer
|
||||
{
|
||||
public static Task<TResult?> Show<TView, TViewModel, TResult>(TViewModel vm, DefaultDrawerOptions? options = null)
|
||||
public static Task<DialogResult?> Show<TView, TViewModel>(TViewModel vm, string? hostId = null, DefaultDrawerOptions? options = null)
|
||||
where TView: Control, new()
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(null);
|
||||
if (host is null) return Task.FromResult(default(TResult));
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
if (host is null) return Task.FromResult(default(DialogResult?));
|
||||
var drawer = new DefaultDrawerControl()
|
||||
{
|
||||
Content = new TView(),
|
||||
@@ -18,13 +18,13 @@ public static class Drawer
|
||||
};
|
||||
ConfigureDefaultDrawer(drawer, options);
|
||||
host.AddDrawer(drawer);
|
||||
return drawer.ShowAsync<TResult>();
|
||||
return drawer.ShowAsync<DialogResult?>();
|
||||
}
|
||||
|
||||
public static Task<TResult?> ShowCustom<TView, TViewModel, TResult>(TViewModel vm, CustomDrawerOptions? options = null)
|
||||
public static Task<TResult?> ShowCustom<TView, TViewModel, TResult>(TViewModel vm, string? hostId = null, CustomDrawerOptions? options = null)
|
||||
where TView: Control, new()
|
||||
{
|
||||
var host = OverlayDialogManager.GetHost(null);
|
||||
var host = OverlayDialogManager.GetHost(hostId);
|
||||
if (host is null) return Task.FromResult(default(TResult));
|
||||
var dialog = new CustomDrawerControl()
|
||||
{
|
||||
|
||||
@@ -32,9 +32,17 @@ public partial class OverlayDialogHost
|
||||
SetDrawerPosition(control);
|
||||
control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDrawerControlClosing);
|
||||
var animation = CreateAnimation(control.Bounds.Size, control.Position, true);
|
||||
if (mask is null)
|
||||
{
|
||||
await animation.RunAsync(control);
|
||||
}
|
||||
else
|
||||
{
|
||||
await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void SetDrawerPosition(DrawerControlBase control)
|
||||
{
|
||||
if(control.Position is Position.Left or Position.Right)
|
||||
@@ -59,7 +67,7 @@ public partial class OverlayDialogHost
|
||||
control.Height = newSize.Height;
|
||||
SetLeft(control, 0);
|
||||
}
|
||||
else if (control.Position == Position.Bottom)
|
||||
else if (control.Position == Position.Top)
|
||||
{
|
||||
control.Width = newSize.Width;
|
||||
SetTop(control, 0);
|
||||
|
||||
Reference in New Issue
Block a user