feat: add default template.

This commit is contained in:
rabbitism
2024-01-10 22:38:50 +08:00
parent abb1bffaeb
commit 81d54d3b28
11 changed files with 117 additions and 5 deletions

View File

@@ -0,0 +1,41 @@
<ResourceDictionary xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:u="https://irihi.tech/ursa">
<!-- Add Resources Here -->
<ControlTheme TargetType="u:MessageBoxWindow" x:Key="{x:Type u:MessageBoxWindow}">
<Setter Property="Background" Value="{DynamicResource WindowDefaultBackground}" />
<Setter Property="TransparencyBackgroundFallback" Value="{DynamicResource WindowDefaultBackground}" />
<Setter Property="Foreground" Value="{DynamicResource WindowDefaultForeground}" />
<Setter Property="FontSize" Value="{DynamicResource DefaultFontSize}" />
<Setter Property="FontFamily" Value="{DynamicResource DefaultFontFamily}" />
<Setter Property="Padding" Value="48 24"></Setter>
<Setter Property="MinHeight" Value="300"></Setter>
<Setter Property="SizeToContent" Value="WidthAndHeight"></Setter>
<Setter Property="WindowStartupLocation" Value="CenterOwner"></Setter>
<Setter Property="ExtendClientAreaTitleBarHeightHint" Value="48"></Setter>
<Setter Property="ExtendClientAreaToDecorationsHint" Value="True"></Setter>
<Setter Property="SystemDecorations" Value="BorderOnly"></Setter>
<Setter Property="CanResize" Value="True"></Setter>
<Setter Property="Template">
<ControlTemplate TargetType="u:MessageBoxWindow">
<Panel>
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
<Border Background="{TemplateBinding Background}" IsHitTestVisible="False" />
<Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" />
<VisualLayerManager>
<VisualLayerManager.ChromeOverlayLayer>
<TitleBar />
</VisualLayerManager.ChromeOverlayLayer>
<ContentPresenter Grid.Row="0"
Name="PART_ContentPresenter"
Margin="{TemplateBinding Padding}"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</VisualLayerManager>
</Panel>
</ControlTemplate>
</Setter>
</ControlTheme>
</ResourceDictionary>

View File

@@ -11,6 +11,7 @@
<ResourceInclude Source="IPv4Box.axaml" />
<ResourceInclude Source="KeyGestureInput.axaml" />
<ResourceInclude Source="Loading.axaml" />
<ResourceInclude Source="MessageBoxWindow.axaml" />
<ResourceInclude Source="Navigation.axaml" />
<ResourceInclude Source="Pagination.axaml" />
<ResourceInclude Source="TagInput.axaml" />

View File

@@ -1,12 +1,28 @@
using Avalonia;
using Avalonia.Controls.ApplicationLifetimes;
namespace Ursa.Controls.MessageBox;
namespace Ursa.Controls;
public static class MessageBox
{
public static async Task ShowAsync(string message)
{
var messageWindow = new MessageBoxWindow();
var messageWindow = new MessageBoxWindow()
{
Content = message
};
var lifetime = Application.Current?.ApplicationLifetime;
if (lifetime is IClassicDesktopStyleApplicationLifetime classLifetime)
{
var main = classLifetime.MainWindow;
if (main is null)
{
messageWindow.Show();
}
else
{
await messageWindow.ShowDialog(main);
}
}
}
}

View File

@@ -1,7 +1,7 @@
using Avalonia.Controls;
using Avalonia.Platform;
namespace Ursa.Controls.MessageBox;
namespace Ursa.Controls;
public class MessageBoxWindow: Window
{
@@ -9,7 +9,6 @@ public class MessageBoxWindow: Window
static MessageBoxWindow()
{
ExtendClientAreaChromeHintsProperty.OverrideDefaultValue<MessageBoxWindow>(ExtendClientAreaChromeHints
.NoChrome);
}
}