feat: WIP

This commit is contained in:
rabbitism
2024-01-22 21:35:01 +08:00
parent c969842870
commit 611e2bc84e
3 changed files with 36 additions and 3 deletions

View File

@@ -14,7 +14,7 @@
Theme="{DynamicResource CardBorder}">
<Grid RowDefinitions="Auto, *, Auto">
<StackPanel Grid.Row="0" HorizontalAlignment="Right">
<Button Name="{x:Static u:DialogControl.PART_CloseButton}">Close</Button>
<Button Name="{x:Static u:DialogControl.PART_CloseButton}" >Close</Button>
</StackPanel>
<ContentPresenter
Grid.Row="0"
@@ -58,8 +58,8 @@
<Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" />
<ChromeOverlayLayer />
<Grid RowDefinitions="Auto, *, Auto">
<Button Name="{x:Static u:DialogWindow.PART_CloseButton}" VerticalAlignment="Top">Close</Button>
<ContentPresenter Content="{TemplateBinding Content}" />
<Button Name="{x:Static u:DialogWindow.PART_CloseButton}" VerticalAlignment="Top" HorizontalAlignment="Right">Close</Button>
<ContentPresenter Grid.Row="0" Grid.RowSpan="2" Content="{TemplateBinding Content}" />
</Grid>
</Panel>
</ControlTemplate>

View File

@@ -1,6 +1,7 @@
using Avalonia.Controls;
using Avalonia.Controls.Metadata;
using Avalonia.Controls.Primitives;
using Avalonia.Input;
using Avalonia.Interactivity;
namespace Ursa.Controls;
@@ -59,4 +60,9 @@ public class DialogWindow: Window
Close(null);
}
}
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
this.BeginMoveDrag(e);
}
}

View File

@@ -4,6 +4,7 @@ using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Avalonia.Controls.Shapes;
using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.Media;
using Avalonia.Utilities;
using Avalonia.VisualTree;
@@ -36,6 +37,24 @@ public class OverlayDialogHost: Canvas
{
base.OnAttachedToVisualTree(e);
OverlayDialogManager.RegisterOverlayDialogHost(this, HostId);
this.Children.Add(new Border()
{
HorizontalAlignment = HorizontalAlignment.Stretch,
VerticalAlignment = VerticalAlignment.Stretch,
Background = Brushes.Black,
Opacity = 0.3,
IsVisible = false,
});
}
protected override void OnSizeChanged(SizeChangedEventArgs e)
{
base.OnSizeChanged(e);
if (this.Children.Count > 0)
{
this.Children[0].Width = this.Bounds.Width;
this.Children[0].Height = this.Bounds.Height;
}
}
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
@@ -85,6 +104,10 @@ public class OverlayDialogHost: Canvas
{
this.Children.Add(control);
control.OnClose += OnDialogClose;
if (this.Children.Count > 1)
{
this.Children[0].IsVisible = true;
}
}
private void OnDialogClose(object sender, object? e)
@@ -93,6 +116,10 @@ public class OverlayDialogHost: Canvas
{
this.Children.Remove(control);
control.OnClose -= OnDialogClose;
if (this.Children.Count == 1)
{
this.Children[0].IsVisible = false;
}
}
}