fix: update demo.
This commit is contained in:
@@ -9,10 +9,5 @@
|
|||||||
x:Class="Ursa.Demo.Dialogs.PlainDialog">
|
x:Class="Ursa.Demo.Dialogs.PlainDialog">
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<Calendar SelectedDate="{Binding Date}" ></Calendar>
|
<Calendar SelectedDate="{Binding Date}" ></Calendar>
|
||||||
<ComboBox>
|
|
||||||
<ComboBoxItem>A</ComboBoxItem>
|
|
||||||
<ComboBoxItem>B</ComboBoxItem>
|
|
||||||
<ComboBoxItem>C</ComboBoxItem>
|
|
||||||
</ComboBox>
|
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
</UserControl>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,18 +1,99 @@
|
|||||||
<UserControl xmlns="https://github.com/avaloniaui"
|
<UserControl
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
x:Class="Ursa.Demo.Pages.DrawerDemo"
|
||||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
mc:Ignorable="d" d:DesignWidth="800"
|
xmlns:common="clr-namespace:Ursa.Common;assembly=Ursa"
|
||||||
xmlns:vm="clr-namespace:Ursa.Demo.ViewModels;assembly=Ursa.Demo"
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||||
xmlns:u="https://irihi.tech/ursa"
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||||
xmlns:common="clr-namespace:Ursa.Common;assembly=Ursa"
|
xmlns:u="https://irihi.tech/ursa"
|
||||||
x:DataType="vm:DrawerDemoViewModel"
|
xmlns:vm="clr-namespace:Ursa.Demo.ViewModels;assembly=Ursa.Demo"
|
||||||
x:CompileBindings="True"
|
d:DesignHeight="450"
|
||||||
d:DesignHeight="450"
|
d:DesignWidth="800"
|
||||||
x:Class="Ursa.Demo.Pages.DrawerDemo">
|
x:CompileBindings="True"
|
||||||
<StackPanel HorizontalAlignment="Left" >
|
x:DataType="vm:DrawerDemoViewModel"
|
||||||
<u:EnumSelector EnumType="{x:Type common:Position}" Value="{Binding SelectedPosition}"></u:EnumSelector>
|
mc:Ignorable="d">
|
||||||
<Button Content="Call Drawer" HorizontalAlignment="Stretch" Command="{Binding OpenDrawerCommand}"></Button>
|
<Grid ColumnDefinitions="Auto, *">
|
||||||
<Button Content="Default Drawer" Command="{Binding OpenDefaultDrawerCommand}"></Button>
|
<TabControl Grid.Column="0" Width="300">
|
||||||
</StackPanel>
|
<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>
|
</UserControl>
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Avalonia.Controls;
|
using Avalonia.Controls;
|
||||||
@@ -12,33 +14,54 @@ namespace Ursa.Demo.ViewModels;
|
|||||||
|
|
||||||
public partial class DrawerDemoViewModel: ObservableObject
|
public partial class DrawerDemoViewModel: ObservableObject
|
||||||
{
|
{
|
||||||
public ICommand OpenDrawerCommand { get; set; }
|
public ICommand ShowDialogCommand { get; set; }
|
||||||
public ICommand OpenDefaultDrawerCommand { get; set; }
|
public ICommand ShowCustomDialogCommand { get; set; }
|
||||||
|
|
||||||
[ObservableProperty] private Position _selectedPosition;
|
[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()
|
public DrawerDemoViewModel()
|
||||||
{
|
{
|
||||||
OpenDrawerCommand = new AsyncRelayCommand(OpenDrawer);
|
ShowDialogCommand = new AsyncRelayCommand(ShowDefaultDialog);
|
||||||
OpenDefaultDrawerCommand = new AsyncRelayCommand(OpenDefaultDrawer);
|
ShowCustomDialogCommand = new AsyncRelayCommand(ShowCustomDrawer);
|
||||||
SelectedPosition = Position.Right;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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>(
|
||||||
Buttons = DialogButton.OKCancel,
|
vm,
|
||||||
Position = SelectedPosition,
|
IsGlobal ? null : "LocalHost",
|
||||||
Title = "Please select a date",
|
new DefaultDrawerOptions()
|
||||||
CanClickOnMaskToClose = false,
|
{
|
||||||
});
|
Title = "Please select a date",
|
||||||
|
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(),
|
var vm = new DialogWithActionViewModel();
|
||||||
new CustomDrawerOptions() { Position = SelectedPosition, MinWidth = 400, MinHeight = 400});
|
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"
|
BorderThickness="1 0 0 0"
|
||||||
IsHitTestVisible="True"
|
IsHitTestVisible="True"
|
||||||
Theme="{DynamicResource CardBorder}">
|
Theme="{DynamicResource CardBorder}">
|
||||||
<Border ClipToBounds="True" CornerRadius="12 0 0 12">
|
<Border ClipToBounds="True" CornerRadius="{Binding #PART_Root.CornerRadius}">
|
||||||
<Grid RowDefinitions="Auto, *">
|
<Grid RowDefinitions="Auto, *">
|
||||||
<ContentPresenter
|
<ContentPresenter
|
||||||
Name="PART_ContentPresenter"
|
Name="PART_ContentPresenter"
|
||||||
@@ -80,7 +80,7 @@
|
|||||||
BorderThickness="1 0 0 0"
|
BorderThickness="1 0 0 0"
|
||||||
IsHitTestVisible="True"
|
IsHitTestVisible="True"
|
||||||
Theme="{DynamicResource CardBorder}">
|
Theme="{DynamicResource CardBorder}">
|
||||||
<Border ClipToBounds="True" CornerRadius="{TemplateBinding CornerRadius}">
|
<Border ClipToBounds="True" CornerRadius="{Binding #PART_Root.CornerRadius}">
|
||||||
<Grid RowDefinitions="Auto, *, Auto">
|
<Grid RowDefinitions="Auto, *, Auto">
|
||||||
<ScrollViewer Grid.Row="1">
|
<ScrollViewer Grid.Row="1">
|
||||||
<ContentPresenter
|
<ContentPresenter
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ using Avalonia.Controls.Metadata;
|
|||||||
using Avalonia.Controls.Primitives;
|
using Avalonia.Controls.Primitives;
|
||||||
using Avalonia.Interactivity;
|
using Avalonia.Interactivity;
|
||||||
using Ursa.Common;
|
using Ursa.Common;
|
||||||
|
using Ursa.EventArgs;
|
||||||
|
|
||||||
namespace Ursa.Controls;
|
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 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()
|
where TView: Control, new()
|
||||||
{
|
{
|
||||||
var host = OverlayDialogManager.GetHost(null);
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
if (host is null) return Task.FromResult(default(TResult));
|
if (host is null) return Task.FromResult(default(DialogResult?));
|
||||||
var drawer = new DefaultDrawerControl()
|
var drawer = new DefaultDrawerControl()
|
||||||
{
|
{
|
||||||
Content = new TView(),
|
Content = new TView(),
|
||||||
@@ -18,13 +18,13 @@ public static class Drawer
|
|||||||
};
|
};
|
||||||
ConfigureDefaultDrawer(drawer, options);
|
ConfigureDefaultDrawer(drawer, options);
|
||||||
host.AddDrawer(drawer);
|
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()
|
where TView: Control, new()
|
||||||
{
|
{
|
||||||
var host = OverlayDialogManager.GetHost(null);
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
if (host is null) return Task.FromResult(default(TResult));
|
if (host is null) return Task.FromResult(default(TResult));
|
||||||
var dialog = new CustomDrawerControl()
|
var dialog = new CustomDrawerControl()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -32,7 +32,15 @@ public partial class OverlayDialogHost
|
|||||||
SetDrawerPosition(control);
|
SetDrawerPosition(control);
|
||||||
control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDrawerControlClosing);
|
control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDrawerControlClosing);
|
||||||
var animation = CreateAnimation(control.Bounds.Size, control.Position, true);
|
var animation = CreateAnimation(control.Bounds.Size, control.Position, true);
|
||||||
await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask));
|
if (mask is null)
|
||||||
|
{
|
||||||
|
await animation.RunAsync(control);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetDrawerPosition(DrawerControlBase control)
|
private void SetDrawerPosition(DrawerControlBase control)
|
||||||
@@ -59,7 +67,7 @@ public partial class OverlayDialogHost
|
|||||||
control.Height = newSize.Height;
|
control.Height = newSize.Height;
|
||||||
SetLeft(control, 0);
|
SetLeft(control, 0);
|
||||||
}
|
}
|
||||||
else if (control.Position == Position.Bottom)
|
else if (control.Position == Position.Top)
|
||||||
{
|
{
|
||||||
control.Width = newSize.Width;
|
control.Width = newSize.Width;
|
||||||
SetTop(control, 0);
|
SetTop(control, 0);
|
||||||
|
|||||||
Reference in New Issue
Block a user