feat: implement closing related features.
This commit is contained in:
@@ -1,8 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using Avalonia.Controls;
|
|
||||||
using Avalonia.Controls.Shapes;
|
|
||||||
using CommunityToolkit.Mvvm.ComponentModel;
|
using CommunityToolkit.Mvvm.ComponentModel;
|
||||||
using CommunityToolkit.Mvvm.Input;
|
using CommunityToolkit.Mvvm.Input;
|
||||||
using Ursa.Controls;
|
using Ursa.Controls;
|
||||||
@@ -30,11 +28,11 @@ public class DialogDemoViewModel: ObservableObject
|
|||||||
|
|
||||||
private async Task ShowGlobalOverlayDialog()
|
private async Task ShowGlobalOverlayDialog()
|
||||||
{
|
{
|
||||||
await DialogBox.ShowOverlayAsync<Banner, DateTime>(DateTime.Now, "GlobalHost");
|
await DialogBox.ShowOverlayAsync<ButtonGroupDemo, ButtonGroupDemoViewModel>(new ButtonGroupDemoViewModel(), "GlobalHost");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ShowLocalOverlayDialog()
|
private async Task ShowLocalOverlayDialog()
|
||||||
{
|
{
|
||||||
await DialogBox.ShowOverlayAsync<Banner, DateTime>(DateTime.Now, "LocalHost");
|
await DialogBox.ShowOverlayAsync<ButtonGroupDemo, ButtonGroupDemoViewModel>(new ButtonGroupDemoViewModel(), "LocalHost");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,13 +1,29 @@
|
|||||||
<ResourceDictionary xmlns="https://github.com/avaloniaui"
|
<ResourceDictionary
|
||||||
|
xmlns="https://github.com/avaloniaui"
|
||||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
xmlns:u="https://irihi.tech/ursa">
|
xmlns:u="https://irihi.tech/ursa">
|
||||||
<!-- Add Resources Here -->
|
<!-- Add Resources Here -->
|
||||||
<ControlTheme x:Key="{x:Type u:DialogControl}" TargetType="u:DialogControl">
|
<ControlTheme x:Key="{x:Type u:DialogControl}" TargetType="u:DialogControl">
|
||||||
<Setter Property="Template">
|
<Setter Property="Template">
|
||||||
<ControlTemplate TargetType="u:DialogControl">
|
<ControlTemplate TargetType="u:DialogControl">
|
||||||
<Border HorizontalAlignment="Center" VerticalAlignment="Center" Theme="{DynamicResource CardBorder}" Width="100" Height="100" IsHitTestVisible="True">
|
<Border
|
||||||
|
Classes="Shadow"
|
||||||
|
HorizontalAlignment="Center"
|
||||||
|
VerticalAlignment="Center"
|
||||||
|
IsHitTestVisible="True"
|
||||||
|
Theme="{DynamicResource CardBorder}">
|
||||||
<Grid RowDefinitions="Auto, *, Auto">
|
<Grid RowDefinitions="Auto, *, Auto">
|
||||||
<ContentPresenter Content="{TemplateBinding Content}"></ContentPresenter>
|
<StackPanel Grid.Row="0" HorizontalAlignment="Right">
|
||||||
|
<Button Name="{x:Static u:DialogControl.PART_CloseButton}">Close</Button>
|
||||||
|
</StackPanel>
|
||||||
|
<ContentPresenter
|
||||||
|
Grid.Row="0"
|
||||||
|
Grid.RowSpan="2"
|
||||||
|
Content="{TemplateBinding Content}" />
|
||||||
|
<StackPanel Grid.Row="2">
|
||||||
|
<Button>OK</Button>
|
||||||
|
<Button>Cancel</Button>
|
||||||
|
</StackPanel>
|
||||||
</Grid>
|
</Grid>
|
||||||
</Border>
|
</Border>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
@@ -26,11 +42,15 @@
|
|||||||
<Setter Property="WindowStartupLocation" Value="CenterOwner" />
|
<Setter Property="WindowStartupLocation" Value="CenterOwner" />
|
||||||
<Setter Property="ExtendClientAreaTitleBarHeightHint" Value="1" />
|
<Setter Property="ExtendClientAreaTitleBarHeightHint" Value="1" />
|
||||||
<Setter Property="ExtendClientAreaToDecorationsHint" Value="True" />
|
<Setter Property="ExtendClientAreaToDecorationsHint" Value="True" />
|
||||||
<Setter Property="ExtendClientAreaChromeHints" Value="SystemChrome"/>
|
<Setter Property="ExtendClientAreaChromeHints" Value="SystemChrome" />
|
||||||
<Setter Property="SystemDecorations">
|
<Setter Property="SystemDecorations">
|
||||||
<OnPlatform >
|
<OnPlatform>
|
||||||
<OnPlatform.Windows><SystemDecorations>Full</SystemDecorations></OnPlatform.Windows>
|
<OnPlatform.Windows>
|
||||||
<OnPlatform.Default><SystemDecorations>BorderOnly</SystemDecorations></OnPlatform.Default>
|
<SystemDecorations>Full</SystemDecorations>
|
||||||
|
</OnPlatform.Windows>
|
||||||
|
<OnPlatform.Default>
|
||||||
|
<SystemDecorations>BorderOnly</SystemDecorations>
|
||||||
|
</OnPlatform.Default>
|
||||||
</OnPlatform>
|
</OnPlatform>
|
||||||
</Setter>
|
</Setter>
|
||||||
<Setter Property="CanResize" Value="False" />
|
<Setter Property="CanResize" Value="False" />
|
||||||
@@ -40,10 +60,10 @@
|
|||||||
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
|
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
|
||||||
<Border Background="{TemplateBinding Background}" IsHitTestVisible="False" />
|
<Border Background="{TemplateBinding Background}" IsHitTestVisible="False" />
|
||||||
<Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" />
|
<Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" />
|
||||||
<ChromeOverlayLayer></ChromeOverlayLayer>
|
<ChromeOverlayLayer />
|
||||||
<Grid RowDefinitions="Auto, *, Auto">
|
<Grid RowDefinitions="Auto, *, Auto">
|
||||||
<Button Name="{x:Static u:DialogWindow.PART_CloseButton}" VerticalAlignment="Top">Close</Button>
|
<Button Name="{x:Static u:DialogWindow.PART_CloseButton}" VerticalAlignment="Top">Close</Button>
|
||||||
<ContentPresenter Content="{TemplateBinding Content}"></ContentPresenter>
|
<ContentPresenter Content="{TemplateBinding Content}" />
|
||||||
</Grid>
|
</Grid>
|
||||||
</Panel>
|
</Panel>
|
||||||
</ControlTemplate>
|
</ControlTemplate>
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ public static class DialogBox
|
|||||||
};
|
};
|
||||||
t.DataContext = vm;
|
t.DataContext = vm;
|
||||||
var host = OverlayDialogManager.GetOverlayDialogHost(hostId);
|
var host = OverlayDialogManager.GetOverlayDialogHost(hostId);
|
||||||
host?.Children.Add(t);
|
host?.AddDialog(t);
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -13,15 +13,36 @@ public class DialogControl: ContentControl
|
|||||||
|
|
||||||
|
|
||||||
private Button? _closeButton;
|
private Button? _closeButton;
|
||||||
public event EventHandler OnClose;
|
public event EventHandler<object?> OnClose;
|
||||||
|
|
||||||
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
|
||||||
{
|
{
|
||||||
base.OnApplyTemplate(e);
|
base.OnApplyTemplate(e);
|
||||||
|
if (_closeButton != null)
|
||||||
|
{
|
||||||
|
_closeButton.Click -= Close;
|
||||||
|
}
|
||||||
|
_closeButton = e.NameScope.Find<Button>(PART_CloseButton);
|
||||||
|
if (_closeButton is not null)
|
||||||
|
{
|
||||||
|
_closeButton.Click += Close;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Show()
|
public void Show()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void Close(object sender, object args)
|
||||||
|
{
|
||||||
|
if (this.DataContext is IDialogContext context)
|
||||||
|
{
|
||||||
|
OnClose?.Invoke(this, context.DefaultCloseResult);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
OnClose?.Invoke(this, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
namespace Ursa.Controls;
|
namespace Ursa.Controls;
|
||||||
|
|
||||||
public record OverlayDialogOptions
|
public record DialogOptions
|
||||||
{
|
{
|
||||||
public bool ShowCloseButton { get; set; } = true;
|
public bool ShowCloseButton { get; set; } = true;
|
||||||
}
|
}
|
||||||
@@ -84,6 +84,17 @@ public class OverlayDialogHost: Canvas
|
|||||||
public void AddDialog(DialogControl control)
|
public void AddDialog(DialogControl control)
|
||||||
{
|
{
|
||||||
this.Children.Add(control);
|
this.Children.Add(control);
|
||||||
|
control.OnClose += OnDialogClose;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDialogClose(object sender, object? e)
|
||||||
|
{
|
||||||
|
if (sender is DialogControl control)
|
||||||
|
{
|
||||||
|
this.Children.Remove(control);
|
||||||
|
control.OnClose -= OnDialogClose;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddModalDialog(DialogControl control)
|
public void AddModalDialog(DialogControl control)
|
||||||
|
|||||||
Reference in New Issue
Block a user