feat: make drawer api similar to dialog.
This commit is contained in:
@@ -23,13 +23,13 @@
|
|||||||
OffContent="Local"
|
OffContent="Local"
|
||||||
OnContent="Global" />
|
OnContent="Global" />
|
||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
Content="ShowMask"
|
Content="Modal"
|
||||||
IsChecked="{Binding ShowMask}"
|
IsChecked="{Binding IsModal}"
|
||||||
OffContent="No"
|
OffContent="No"
|
||||||
OnContent="Yes" />
|
OnContent="Yes" />
|
||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
Content="ClickOnMaskToClose"
|
Content="CanLightDismiss"
|
||||||
IsChecked="{Binding CanCloseMaskToClose}"
|
IsChecked="{Binding CanLightDismiss}"
|
||||||
OffContent="No"
|
OffContent="No"
|
||||||
OnContent="Yes" />
|
OnContent="Yes" />
|
||||||
<StackPanel Orientation="Horizontal">
|
<StackPanel Orientation="Horizontal">
|
||||||
@@ -56,13 +56,13 @@
|
|||||||
OffContent="Local"
|
OffContent="Local"
|
||||||
OnContent="Global" />
|
OnContent="Global" />
|
||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
Content="ClickOnMaskToClose"
|
Content="CanLightDismiss"
|
||||||
IsChecked="{Binding CanCloseMaskToClose}"
|
IsChecked="{Binding CanLightDismiss}"
|
||||||
OffContent="No"
|
OffContent="No"
|
||||||
OnContent="Yes" />
|
OnContent="Yes" />
|
||||||
<ToggleSwitch
|
<ToggleSwitch
|
||||||
Content="ShowMask"
|
Content="Modal"
|
||||||
IsChecked="{Binding ShowMask}"
|
IsChecked="{Binding IsModal}"
|
||||||
OffContent="No"
|
OffContent="No"
|
||||||
OnContent="Yes" />
|
OnContent="Yes" />
|
||||||
<Button Command="{Binding ShowCustomDialogCommand}" Content="Show Custom Drawer" />
|
<Button Command="{Binding ShowCustomDialogCommand}" Content="Show Custom Drawer" />
|
||||||
|
|||||||
@@ -20,10 +20,10 @@ public partial class DrawerDemoViewModel: ObservableObject
|
|||||||
[ObservableProperty] private Position _selectedPosition;
|
[ObservableProperty] private Position _selectedPosition;
|
||||||
[ObservableProperty] private DialogButton _selectedButton;
|
[ObservableProperty] private DialogButton _selectedButton;
|
||||||
[ObservableProperty] private bool _isGlobal;
|
[ObservableProperty] private bool _isGlobal;
|
||||||
[ObservableProperty] private bool _canCloseMaskToClose;
|
[ObservableProperty] private bool _canLightDismiss;
|
||||||
[ObservableProperty] private DialogResult? _defaultResult;
|
[ObservableProperty] private DialogResult? _defaultResult;
|
||||||
[ObservableProperty] private bool _result;
|
[ObservableProperty] private bool _result;
|
||||||
[ObservableProperty] private bool _showMask;
|
[ObservableProperty] private bool _isModal;
|
||||||
[ObservableProperty] private DateTime? _date;
|
[ObservableProperty] private DateTime? _date;
|
||||||
|
|
||||||
|
|
||||||
@@ -36,32 +36,60 @@ public partial class DrawerDemoViewModel: ObservableObject
|
|||||||
private async Task ShowDefaultDialog()
|
private async Task ShowDefaultDialog()
|
||||||
{
|
{
|
||||||
var vm = new PlainDialogViewModel();
|
var vm = new PlainDialogViewModel();
|
||||||
DefaultResult = await Drawer.Show<PlainDialog, PlainDialogViewModel>(
|
if (IsModal)
|
||||||
vm,
|
{
|
||||||
IsGlobal ? null : "LocalHost",
|
DefaultResult = await Drawer.ShowModal<PlainDialog, PlainDialogViewModel>(
|
||||||
new DefaultDrawerOptions()
|
vm,
|
||||||
{
|
IsGlobal ? null : "LocalHost",
|
||||||
Title = "Please select a date",
|
new DrawerOptions()
|
||||||
Position = SelectedPosition,
|
{
|
||||||
Buttons = SelectedButton,
|
Title = "Please select a date",
|
||||||
CanClickOnMaskToClose = CanCloseMaskToClose,
|
Position = SelectedPosition,
|
||||||
ShowMask = ShowMask,
|
Buttons = SelectedButton,
|
||||||
});
|
CanLightDismiss = CanLightDismiss,
|
||||||
Date = vm.Date;
|
});
|
||||||
|
Date = vm.Date;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Drawer.Show<PlainDialog, PlainDialogViewModel>(
|
||||||
|
vm,
|
||||||
|
IsGlobal ? null : "LocalHost",
|
||||||
|
new DrawerOptions()
|
||||||
|
{
|
||||||
|
Title = "Please select a date",
|
||||||
|
Position = SelectedPosition,
|
||||||
|
Buttons = SelectedButton,
|
||||||
|
CanLightDismiss = CanLightDismiss,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ShowCustomDrawer()
|
private async Task ShowCustomDrawer()
|
||||||
{
|
{
|
||||||
var vm = new DialogWithActionViewModel();
|
var vm = new DialogWithActionViewModel();
|
||||||
Result = await Drawer.ShowCustom<DialogWithAction, DialogWithActionViewModel, bool>(
|
if (IsModal)
|
||||||
vm,
|
{
|
||||||
IsGlobal ? null : "LocalHost",
|
Result = await Drawer.ShowCustomModal<DialogWithAction, DialogWithActionViewModel, bool>(
|
||||||
new CustomDrawerOptions()
|
vm,
|
||||||
{
|
IsGlobal ? null : "LocalHost",
|
||||||
Position = SelectedPosition,
|
new DrawerOptions()
|
||||||
CanClickOnMaskToClose = CanCloseMaskToClose,
|
{
|
||||||
ShowMask = ShowMask,
|
Position = SelectedPosition,
|
||||||
});
|
CanLightDismiss = CanLightDismiss,
|
||||||
Date = vm.Date;
|
});
|
||||||
|
Date = vm.Date;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Drawer.ShowCustom<DialogWithAction, DialogWithActionViewModel>(
|
||||||
|
vm,
|
||||||
|
IsGlobal ? null : "LocalHost",
|
||||||
|
new DrawerOptions()
|
||||||
|
{
|
||||||
|
Position = SelectedPosition,
|
||||||
|
CanLightDismiss = CanLightDismiss,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -8,7 +8,8 @@
|
|||||||
Title="Ursa.PrismDialogDemo">
|
Title="Ursa.PrismDialogDemo">
|
||||||
<Grid>
|
<Grid>
|
||||||
<StackPanel>
|
<StackPanel>
|
||||||
<Button Click="Button_OnClick">Show Dialog</Button>
|
<Button Click="DialogButton_OnClick">Show Dialog</Button>
|
||||||
|
<Button Click="DrawerButton_OnClick"></Button>
|
||||||
</StackPanel>
|
</StackPanel>
|
||||||
<u:OverlayDialogHost/>
|
<u:OverlayDialogHost/>
|
||||||
</Grid>
|
</Grid>
|
||||||
|
|||||||
@@ -7,15 +7,22 @@ namespace Ursa.PrismDialogDemo;
|
|||||||
|
|
||||||
public partial class MainWindow : Window
|
public partial class MainWindow : Window
|
||||||
{
|
{
|
||||||
private IUrsaOverlayDialogService _ursa;
|
private IUrsaOverlayDialogService _dialogService;
|
||||||
public MainWindow(IUrsaOverlayDialogService ursa)
|
private IUrsaDrawerService _drawerService;
|
||||||
|
public MainWindow(IUrsaOverlayDialogService dialogService, IUrsaDrawerService drawerService)
|
||||||
{
|
{
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
_ursa = ursa;
|
_dialogService = dialogService;
|
||||||
|
_drawerService = drawerService;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Button_OnClick(object? sender, RoutedEventArgs e)
|
private void DialogButton_OnClick(object? sender, RoutedEventArgs e)
|
||||||
{
|
{
|
||||||
_ursa.ShowModal("Default", null, null, null);
|
_dialogService.ShowModal("Default", null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DrawerButton_OnClick(object? sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
_drawerService.ShowModal("Default", null, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -5,6 +5,8 @@ namespace Ursa.PrismExtension;
|
|||||||
|
|
||||||
public interface IUrsaDrawerService
|
public interface IUrsaDrawerService
|
||||||
{
|
{
|
||||||
public Task<DialogResult> ShowDrawer(string viewName, object? vm, string? hostId = null, DefaultDrawerOptions? options = null);
|
public void Show(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null);
|
||||||
public Task<TResult?> ShowCustomDrawer<TResult>(string viewName, object? vm, string? hostId = null, CustomDrawerOptions? options = null);
|
public void ShowCustom<TResult>(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null);
|
||||||
|
public Task<DialogResult> ShowModal(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null);
|
||||||
|
public Task<TResult?> ShowCustomModal<TResult>(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null);
|
||||||
}
|
}
|
||||||
@@ -7,16 +7,27 @@ namespace Ursa.PrismExtension;
|
|||||||
|
|
||||||
public class UrsaDrawerService(IContainerExtension container): IUrsaDrawerService
|
public class UrsaDrawerService(IContainerExtension container): IUrsaDrawerService
|
||||||
{
|
{
|
||||||
public Task<DialogResult> ShowDrawer(string viewName, object? vm, string? hostId = null, DefaultDrawerOptions? options = null)
|
public void Show(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
{
|
{
|
||||||
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
||||||
return Drawer.Show(v, vm, hostId, options);
|
Drawer.Show(v, vm, hostId, options);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task<TResult?> ShowCustomDrawer<TResult>(string viewName, object? vm, string? hostId = null,
|
public void ShowCustom<TResult>(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
CustomDrawerOptions? options = null)
|
|
||||||
{
|
{
|
||||||
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
||||||
return Drawer.ShowCustom<TResult?>(v, vm, hostId, options);
|
Drawer.ShowCustom(v, vm, hostId, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<DialogResult> ShowModal(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
|
{
|
||||||
|
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
||||||
|
return Drawer.ShowModal(v, vm, hostId, options);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<TResult?> ShowCustomModal<TResult>(string viewName, object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
|
{
|
||||||
|
var v = container.Resolve<Control>(UrsaDialogServiceExtension.UrsaDialogViewPrefix + viewName);
|
||||||
|
return Drawer.ShowCustomModal<TResult?>(v, vm, hostId, options);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -7,11 +7,11 @@ namespace Ursa.Controls;
|
|||||||
|
|
||||||
public static class Drawer
|
public static class Drawer
|
||||||
{
|
{
|
||||||
public static Task<DialogResult> Show<TView, TViewModel>(TViewModel vm, string? hostId = null, DefaultDrawerOptions? options = null)
|
public static void Show<TView, TViewModel>(TViewModel vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
where TView: Control, new()
|
where TView: Control, new()
|
||||||
{
|
{
|
||||||
var host = OverlayDialogManager.GetHost(hostId);
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
if (host is null) return Task.FromResult(default(DialogResult));
|
if (host is null) return;
|
||||||
var drawer = new DefaultDrawerControl()
|
var drawer = new DefaultDrawerControl()
|
||||||
{
|
{
|
||||||
Content = new TView(),
|
Content = new TView(),
|
||||||
@@ -19,14 +19,13 @@ public static class Drawer
|
|||||||
};
|
};
|
||||||
ConfigureDefaultDrawer(drawer, options);
|
ConfigureDefaultDrawer(drawer, options);
|
||||||
host.AddDrawer(drawer);
|
host.AddDrawer(drawer);
|
||||||
return drawer.ShowAsync<DialogResult>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<DialogResult> Show(Control control, object? vm, string? hostId = null,
|
public static void Show(Control control, object? vm, string? hostId = null,
|
||||||
DefaultDrawerOptions? options = null)
|
DrawerOptions? options = null)
|
||||||
{
|
{
|
||||||
var host = OverlayDialogManager.GetHost(hostId);
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
if (host is null) return Task.FromResult(default(DialogResult));
|
if (host is null) return;
|
||||||
var drawer = new DefaultDrawerControl()
|
var drawer = new DefaultDrawerControl()
|
||||||
{
|
{
|
||||||
Content = control,
|
Content = control,
|
||||||
@@ -34,13 +33,12 @@ public static class Drawer
|
|||||||
};
|
};
|
||||||
ConfigureDefaultDrawer(drawer, options);
|
ConfigureDefaultDrawer(drawer, options);
|
||||||
host.AddDrawer(drawer);
|
host.AddDrawer(drawer);
|
||||||
return drawer.ShowAsync<DialogResult>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<DialogResult> Show(object? vm, string? hostId = null, DefaultDrawerOptions? options = null)
|
public static void Show(object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
{
|
{
|
||||||
var host = OverlayDialogManager.GetHost(hostId);
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
if (host is null) return Task.FromResult(default(DialogResult));
|
if (host is null) return;
|
||||||
var view = host.GetDataTemplate(vm)?.Build(vm);
|
var view = host.GetDataTemplate(vm)?.Build(vm);
|
||||||
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
||||||
view.DataContext = vm;
|
view.DataContext = vm;
|
||||||
@@ -51,14 +49,60 @@ public static class Drawer
|
|||||||
};
|
};
|
||||||
ConfigureDefaultDrawer(drawer, options);
|
ConfigureDefaultDrawer(drawer, options);
|
||||||
host.AddDrawer(drawer);
|
host.AddDrawer(drawer);
|
||||||
return drawer.ShowAsync<DialogResult>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<TResult?> ShowCustom<TView, TViewModel, TResult>(TViewModel vm, string? hostId = null, CustomDrawerOptions? options = null)
|
public static Task<DialogResult> ShowModal<TView, TViewModel>(TViewModel vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
where TView: Control, new()
|
where TView: Control, new()
|
||||||
{
|
{
|
||||||
var host = OverlayDialogManager.GetHost(hostId);
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
if (host is null) return Task.FromResult(default(TResult));
|
if (host is null) return Task.FromResult(DialogResult.None);
|
||||||
|
var drawer = new DefaultDrawerControl()
|
||||||
|
{
|
||||||
|
Content = new TView(),
|
||||||
|
DataContext = vm,
|
||||||
|
};
|
||||||
|
ConfigureDefaultDrawer(drawer, options);
|
||||||
|
host.AddModalDrawer(drawer);
|
||||||
|
return drawer.ShowAsync<DialogResult>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task<DialogResult> ShowModal(Control control, object? vm, string? hostId = null,
|
||||||
|
DrawerOptions? options = null)
|
||||||
|
{
|
||||||
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
|
if (host is null) return Task.FromResult(DialogResult.None);
|
||||||
|
var drawer = new DefaultDrawerControl()
|
||||||
|
{
|
||||||
|
Content = control,
|
||||||
|
DataContext = vm,
|
||||||
|
};
|
||||||
|
ConfigureDefaultDrawer(drawer, options);
|
||||||
|
host.AddModalDrawer(drawer);
|
||||||
|
return drawer.ShowAsync<DialogResult>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task<DialogResult> ShowModal(object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
|
{
|
||||||
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
|
if (host is null) return Task.FromResult(DialogResult.None);
|
||||||
|
var view = host.GetDataTemplate(vm)?.Build(vm);
|
||||||
|
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
||||||
|
view.DataContext = vm;
|
||||||
|
var drawer = new DefaultDrawerControl()
|
||||||
|
{
|
||||||
|
Content = view,
|
||||||
|
DataContext = vm,
|
||||||
|
};
|
||||||
|
ConfigureDefaultDrawer(drawer, options);
|
||||||
|
host.AddModalDrawer(drawer);
|
||||||
|
return drawer.ShowAsync<DialogResult>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ShowCustom<TView, TViewModel>(TViewModel vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
|
where TView: Control, new()
|
||||||
|
{
|
||||||
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
|
if (host is null) return;
|
||||||
var dialog = new CustomDrawerControl()
|
var dialog = new CustomDrawerControl()
|
||||||
{
|
{
|
||||||
Content = new TView(),
|
Content = new TView(),
|
||||||
@@ -66,13 +110,12 @@ public static class Drawer
|
|||||||
};
|
};
|
||||||
ConfigureCustomDrawer(dialog, options);
|
ConfigureCustomDrawer(dialog, options);
|
||||||
host.AddDrawer(dialog);
|
host.AddDrawer(dialog);
|
||||||
return dialog.ShowAsync<TResult>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<TResult?> ShowCustom<TResult>(Control control, object? vm, string? hostId = null, CustomDrawerOptions? options = null)
|
public static void ShowCustom(Control control, object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
{
|
{
|
||||||
var host = OverlayDialogManager.GetHost(hostId);
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
if (host is null) return Task.FromResult(default(TResult));
|
if (host is null) return;
|
||||||
var dialog = new CustomDrawerControl()
|
var dialog = new CustomDrawerControl()
|
||||||
{
|
{
|
||||||
Content = control,
|
Content = control,
|
||||||
@@ -80,13 +123,12 @@ public static class Drawer
|
|||||||
};
|
};
|
||||||
ConfigureCustomDrawer(dialog, options);
|
ConfigureCustomDrawer(dialog, options);
|
||||||
host.AddDrawer(dialog);
|
host.AddDrawer(dialog);
|
||||||
return dialog.ShowAsync<TResult>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Task<TResult?> ShowCustom<TResult>(object? vm, string? hostId = null, CustomDrawerOptions? options = null)
|
public static void ShowCustom(object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
{
|
{
|
||||||
var host = OverlayDialogManager.GetHost(hostId);
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
if (host is null) return Task.FromResult(default(TResult));
|
if (host is null) return;
|
||||||
var view = host.GetDataTemplate(vm)?.Build(vm);
|
var view = host.GetDataTemplate(vm)?.Build(vm);
|
||||||
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
||||||
view.DataContext = vm;
|
view.DataContext = vm;
|
||||||
@@ -97,17 +139,59 @@ public static class Drawer
|
|||||||
};
|
};
|
||||||
ConfigureCustomDrawer(dialog, options);
|
ConfigureCustomDrawer(dialog, options);
|
||||||
host.AddDrawer(dialog);
|
host.AddDrawer(dialog);
|
||||||
return dialog.ShowAsync<TResult>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Task<TResult?> ShowCustomModal<TView, TViewModel, TResult>(TViewModel vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
private static void ConfigureCustomDrawer(CustomDrawerControl drawer, CustomDrawerOptions? options)
|
where TView: Control, new()
|
||||||
{
|
{
|
||||||
options ??= CustomDrawerOptions.Default;
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
|
if (host is null) return Task.FromResult<TResult?>(default);
|
||||||
|
var dialog = new CustomDrawerControl()
|
||||||
|
{
|
||||||
|
Content = new TView(),
|
||||||
|
DataContext = vm,
|
||||||
|
};
|
||||||
|
ConfigureCustomDrawer(dialog, options);
|
||||||
|
host.AddModalDrawer(dialog);
|
||||||
|
return dialog.ShowAsync<TResult?>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task<TResult?> ShowCustomModal<TResult>(Control control, object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
|
{
|
||||||
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
|
if (host is null) return Task.FromResult<TResult?>(default);
|
||||||
|
var dialog = new CustomDrawerControl()
|
||||||
|
{
|
||||||
|
Content = control,
|
||||||
|
DataContext = vm,
|
||||||
|
};
|
||||||
|
ConfigureCustomDrawer(dialog, options);
|
||||||
|
host.AddModalDrawer(dialog);
|
||||||
|
return dialog.ShowAsync<TResult?>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task<TResult?> ShowCustomModal<TResult>(object? vm, string? hostId = null, DrawerOptions? options = null)
|
||||||
|
{
|
||||||
|
var host = OverlayDialogManager.GetHost(hostId);
|
||||||
|
if (host is null) return Task.FromResult<TResult?>(default);
|
||||||
|
var view = host.GetDataTemplate(vm)?.Build(vm);
|
||||||
|
if (view is null) view = new ContentControl() { Padding = new Thickness(24) };
|
||||||
|
view.DataContext = vm;
|
||||||
|
var dialog = new CustomDrawerControl()
|
||||||
|
{
|
||||||
|
Content = view,
|
||||||
|
DataContext = vm,
|
||||||
|
};
|
||||||
|
ConfigureCustomDrawer(dialog, options);
|
||||||
|
host.AddModalDrawer(dialog);
|
||||||
|
return dialog.ShowAsync<TResult?>();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ConfigureCustomDrawer(CustomDrawerControl drawer, DrawerOptions? options)
|
||||||
|
{
|
||||||
|
options ??= DrawerOptions.Default;
|
||||||
drawer.Position = options.Position;
|
drawer.Position = options.Position;
|
||||||
drawer.CanClickOnMaskToClose = options.CanClickOnMaskToClose;
|
drawer.IsCloseButtonVisible = options.ShowCloseButton;
|
||||||
drawer.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
|
||||||
drawer.ShowMask = options.ShowMask;
|
|
||||||
drawer.CanLightDismiss = options.CanLightDismiss;
|
drawer.CanLightDismiss = options.CanLightDismiss;
|
||||||
if (options.Position == Position.Left || options.Position == Position.Right)
|
if (options.Position == Position.Left || options.Position == Position.Right)
|
||||||
{
|
{
|
||||||
@@ -121,16 +205,14 @@ public static class Drawer
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ConfigureDefaultDrawer(DefaultDrawerControl drawer, DefaultDrawerOptions? options)
|
private static void ConfigureDefaultDrawer(DefaultDrawerControl drawer, DrawerOptions? options)
|
||||||
{
|
{
|
||||||
options ??= DefaultDrawerOptions.Default;
|
options ??= DrawerOptions.Default;
|
||||||
drawer.Position = options.Position;
|
drawer.Position = options.Position;
|
||||||
drawer.CanClickOnMaskToClose = options.CanClickOnMaskToClose;
|
|
||||||
drawer.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
drawer.IsCloseButtonVisible = options.IsCloseButtonVisible;
|
||||||
|
drawer.CanLightDismiss = options.CanLightDismiss;
|
||||||
drawer.Buttons = options.Buttons;
|
drawer.Buttons = options.Buttons;
|
||||||
drawer.Title = options.Title;
|
drawer.Title = options.Title;
|
||||||
drawer.ShowMask = options.ShowMask;
|
|
||||||
drawer.CanLightDismiss = options.CanLightDismiss;
|
|
||||||
if (options.Position == Position.Left || options.Position == Position.Right)
|
if (options.Position == Position.Left || options.Position == Position.Right)
|
||||||
{
|
{
|
||||||
drawer.MinWidth = options.MinWidth ?? 0.0;
|
drawer.MinWidth = options.MinWidth ?? 0.0;
|
||||||
|
|||||||
@@ -15,9 +15,7 @@ namespace Ursa.Controls;
|
|||||||
[TemplatePart(PART_CloseButton, typeof(Button))]
|
[TemplatePart(PART_CloseButton, typeof(Button))]
|
||||||
public abstract class DrawerControlBase: OverlayFeedbackElement
|
public abstract class DrawerControlBase: OverlayFeedbackElement
|
||||||
{
|
{
|
||||||
public const string PART_CloseButton = "PART_CloseButton";
|
public const string PART_CloseButton = "PART_CloseButton";
|
||||||
|
|
||||||
internal bool CanClickOnMaskToClose { get; set; }
|
|
||||||
|
|
||||||
protected internal Button? _closeButton;
|
protected internal Button? _closeButton;
|
||||||
|
|
||||||
@@ -50,7 +48,6 @@ public const string PART_CloseButton = "PART_CloseButton";
|
|||||||
set => SetValue(IsCloseButtonVisibleProperty, value);
|
set => SetValue(IsCloseButtonVisibleProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected internal bool ShowMask { get; set; }
|
|
||||||
protected internal bool CanLightDismiss { get; set; }
|
protected internal bool CanLightDismiss { get; set; }
|
||||||
|
|
||||||
static DrawerControlBase()
|
static DrawerControlBase()
|
||||||
|
|||||||
@@ -1,17 +0,0 @@
|
|||||||
using Ursa.Common;
|
|
||||||
|
|
||||||
namespace Ursa.Controls.Options;
|
|
||||||
|
|
||||||
public class CustomDrawerOptions
|
|
||||||
{
|
|
||||||
internal static CustomDrawerOptions Default => new ();
|
|
||||||
public Position Position { get; set; } = Position.Right;
|
|
||||||
public bool CanClickOnMaskToClose { get; set; } = true;
|
|
||||||
public bool CanLightDismiss { get; set; } = false;
|
|
||||||
public bool ShowMask { get; set; } = true;
|
|
||||||
public bool IsCloseButtonVisible { get; set; } = true;
|
|
||||||
public double? MinWidth { get; set; } = null;
|
|
||||||
public double? MinHeight { get; set; } = null;
|
|
||||||
public double? MaxWidth { get; set; } = null;
|
|
||||||
public double? MaxHeight { get; set; } = null;
|
|
||||||
}
|
|
||||||
@@ -2,13 +2,11 @@
|
|||||||
|
|
||||||
namespace Ursa.Controls.Options;
|
namespace Ursa.Controls.Options;
|
||||||
|
|
||||||
public class DefaultDrawerOptions
|
public class DrawerOptions
|
||||||
{
|
{
|
||||||
internal static DefaultDrawerOptions Default => new ();
|
internal static DrawerOptions Default => new ();
|
||||||
public Position Position { get; set; } = Position.Right;
|
public Position Position { get; set; } = Position.Right;
|
||||||
public bool CanClickOnMaskToClose { get; set; } = true;
|
public bool CanLightDismiss { get; set; } = true;
|
||||||
public bool CanLightDismiss { get; set; } = false;
|
|
||||||
public bool ShowMask { get; set; } = true;
|
|
||||||
public bool IsCloseButtonVisible { get; set; } = true;
|
public bool IsCloseButtonVisible { get; set; } = true;
|
||||||
public double? MinWidth { get; set; } = null;
|
public double? MinWidth { get; set; } = null;
|
||||||
public double? MinHeight { get; set; } = null;
|
public double? MinHeight { get; set; } = null;
|
||||||
@@ -16,4 +14,5 @@ public class DefaultDrawerOptions
|
|||||||
public double? MaxHeight { get; set; } = null;
|
public double? MaxHeight { get; set; } = null;
|
||||||
public DialogButton Buttons { get; set; } = DialogButton.OKCancel;
|
public DialogButton Buttons { get; set; } = DialogButton.OKCancel;
|
||||||
public string? Title { get; set; }
|
public string? Title { get; set; }
|
||||||
|
public bool ShowCloseButton { get; set; } = true;
|
||||||
}
|
}
|
||||||
@@ -15,14 +15,10 @@ public partial class OverlayDialogHost
|
|||||||
internal async void AddDrawer(DrawerControlBase control)
|
internal async void AddDrawer(DrawerControlBase control)
|
||||||
{
|
{
|
||||||
PureRectangle? mask = null;
|
PureRectangle? mask = null;
|
||||||
if (control.ShowMask == false && control.CanLightDismiss)
|
if (control.CanLightDismiss)
|
||||||
{
|
{
|
||||||
mask = CreateOverlayMask(false, true);
|
mask = CreateOverlayMask(false, true);
|
||||||
}
|
}
|
||||||
else if (control.ShowMask)
|
|
||||||
{
|
|
||||||
mask = CreateOverlayMask(control.ShowMask, control.CanClickOnMaskToClose);
|
|
||||||
}
|
|
||||||
_layers.Add(new DialogPair(mask, control));
|
_layers.Add(new DialogPair(mask, control));
|
||||||
ResetZIndices();
|
ResetZIndices();
|
||||||
if(mask is not null)this.Children.Add(mask);
|
if(mask is not null)this.Children.Add(mask);
|
||||||
@@ -40,7 +36,21 @@ public partial class OverlayDialogHost
|
|||||||
{
|
{
|
||||||
await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask));
|
await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
internal async void AddModalDrawer(DrawerControlBase control)
|
||||||
|
{
|
||||||
|
PureRectangle? mask = CreateOverlayMask(true, control.CanLightDismiss);
|
||||||
|
_layers.Add(new DialogPair(mask, control));
|
||||||
|
this.Children.Add(mask);
|
||||||
|
this.Children.Add(control);
|
||||||
|
ResetZIndices();
|
||||||
|
control.Measure(this.Bounds.Size);
|
||||||
|
control.Arrange(new Rect(control.DesiredSize));
|
||||||
|
SetDrawerPosition(control);
|
||||||
|
control.AddHandler(OverlayFeedbackElement.ClosedEvent, OnDrawerControlClosing);
|
||||||
|
var animation = CreateAnimation(control.Bounds.Size, control.Position);
|
||||||
|
await Task.WhenAll(animation.RunAsync(control), _maskAppearAnimation.RunAsync(mask));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void SetDrawerPosition(DrawerControlBase control)
|
private void SetDrawerPosition(DrawerControlBase control)
|
||||||
|
|||||||
Reference in New Issue
Block a user