feat: implement resizing logic.

This commit is contained in:
rabbitism
2024-02-05 22:06:17 +08:00
parent fd85efd895
commit 36c63b6326
6 changed files with 97 additions and 20 deletions

View File

@@ -1,25 +1,43 @@
<UserControl xmlns="https://github.com/avaloniaui" <UserControl
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" x:Class="Ursa.Demo.Dialogs.DialogWithAction"
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"
xmlns:local="clr-namespace:Ursa.Demo.Dialogs" xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
x:DataType="local:DialogWithActionViewModel" xmlns:local="clr-namespace:Ursa.Demo.Dialogs"
x:CompileBindings="True" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Background="{DynamicResource SemiYellow1}" HorizontalAlignment="Stretch"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450" VerticalAlignment="Stretch"
x:Class="Ursa.Demo.Dialogs.DialogWithAction"> d:DesignHeight="450"
<StackPanel Margin="24"> d:DesignWidth="800"
<TextBlock FontSize="16" FontWeight="600" Margin="8" Text="{Binding Title}"></TextBlock> x:CompileBindings="True"
<Calendar SelectedDate="{Binding Date}" ></Calendar> x:DataType="local:DialogWithActionViewModel"
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Spacing="8"> Background="{DynamicResource SemiYellow1}"
<Button Content="Dialog" Command="{Binding DialogCommand}"></Button> mc:Ignorable="d">
<Button Content="OK" Command="{Binding OKCommand}"></Button> <Grid Margin="24" RowDefinitions="Auto, *, Auto">
<Button Content="Cancel" Command="{Binding CancelCommand}"></Button> <TextBlock
Grid.Row="0"
Margin="8"
FontSize="16"
FontWeight="600"
Text="{Binding Title}" />
<Calendar
Grid.Row="1"
HorizontalAlignment="Center"
VerticalAlignment="Top"
SelectedDate="{Binding Date}" />
<StackPanel
Grid.Row="2"
HorizontalAlignment="Right"
Orientation="Horizontal"
Spacing="8">
<Button Command="{Binding DialogCommand}" Content="Dialog" />
<Button Command="{Binding OKCommand}" Content="OK" />
<Button Command="{Binding CancelCommand}" Content="Cancel" />
<ComboBox> <ComboBox>
<ComboBoxItem>A</ComboBoxItem> <ComboBoxItem>A</ComboBoxItem>
<ComboBoxItem>B</ComboBoxItem> <ComboBoxItem>B</ComboBoxItem>
<ComboBoxItem>C</ComboBoxItem> <ComboBoxItem>C</ComboBoxItem>
</ComboBox> </ComboBox>
</StackPanel> </StackPanel>
</StackPanel> </Grid>
</UserControl> </UserControl>

View File

@@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.Input;
using Ursa.Common; using Ursa.Common;
using Ursa.Controls; using Ursa.Controls;
using Ursa.Controls.Options; using Ursa.Controls.Options;
using Ursa.Demo.Dialogs;
namespace Ursa.Demo.ViewModels; namespace Ursa.Demo.ViewModels;
@@ -23,6 +24,7 @@ public partial class DrawerDemoViewModel: ObservableObject
private async Task OpenDrawer() private async Task OpenDrawer()
{ {
await Drawer.ShowCustom<Calendar, string, bool>("Hello World", new CustomDrawerOptions() { Position = SelectedPosition, MinWidth = 400 }); await Drawer.ShowCustom<DialogWithAction, DialogWithActionViewModel, bool>(new DialogWithActionViewModel(),
new CustomDrawerOptions() { Position = SelectedPosition, MinWidth = 400, MinHeight = 400});
} }
} }

View File

@@ -135,6 +135,11 @@
<ControlTheme x:Key="{x:Type u:DefaultDialogControl}" TargetType="u:DefaultDialogControl"> <ControlTheme x:Key="{x:Type u:DefaultDialogControl}" TargetType="u:DefaultDialogControl">
<Setter Property="CornerRadius" Value="12" /> <Setter Property="CornerRadius" Value="12" />
<Setter Property="Transitions">
<Transitions>
<TransformOperationsTransition Duration="0.2" Property="RenderTransform"/>
</Transitions>
</Setter>
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="u:DefaultDialogControl"> <ControlTemplate TargetType="u:DefaultDialogControl">
<Border <Border
@@ -223,6 +228,9 @@
</Border> </Border>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^[IsClosed=True]">
<Setter Property="RenderTransform" Value="scale(0.95)"/>
</Style>
<Style Selector="^[Mode=None]"> <Style Selector="^[Mode=None]">
<Style Selector="^ /template/ PathIcon#PART_Icon"> <Style Selector="^ /template/ PathIcon#PART_Icon">
<Setter Property="IsVisible" Value="False" /> <Setter Property="IsVisible" Value="False" />

View File

@@ -6,7 +6,8 @@
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter> <Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
<Setter Property="Template"> <Setter Property="Template">
<ControlTemplate TargetType="u:CustomDrawerControl"> <ControlTemplate TargetType="u:CustomDrawerControl">
<Border Margin="8 -1 -1 -1" <Border Name="PART_Root"
Margin="8 -1 -1 -1"
Padding="0" Padding="0"
HorizontalAlignment="Stretch" HorizontalAlignment="Stretch"
VerticalAlignment="Stretch" VerticalAlignment="Stretch"
@@ -41,5 +42,25 @@
</Border> </Border>
</ControlTemplate> </ControlTemplate>
</Setter> </Setter>
<Style Selector="^[Position=Right] /template/ Border#PART_Root">
<Setter Property="Margin" Value="8 0 0 0" />
<Setter Property="CornerRadius" Value="12 0 0 12" />
<Setter Property="BorderThickness" Value="1 0 0 0" />
</Style>
<Style Selector="^[Position=Left] /template/ Border#PART_Root">
<Setter Property="Margin" Value="0 0 8 0" />
<Setter Property="CornerRadius" Value="0 12 12 0" />
<Setter Property="BorderThickness" Value="0 0 1 0" />
</Style>
<Style Selector="^[Position=Top] /template/ Border#PART_Root">
<Setter Property="Margin" Value="0 0 0 8" />
<Setter Property="CornerRadius" Value="0 0 12 12" />
<Setter Property="BorderThickness" Value="0 0 0 1" />
</Style>
<Style Selector="^[Position=Bottom] /template/ Border#PART_Root">
<Setter Property="Margin" Value="0 8 0 0" />
<Setter Property="CornerRadius" Value="12 12 0 0" />
<Setter Property="BorderThickness" Value="0 1 0 0" />
</Style>
</ControlTheme> </ControlTheme>
</ResourceDictionary> </ResourceDictionary>

View File

@@ -46,6 +46,30 @@ public partial class OverlayDialogHost
control.Width = this.Bounds.Width; control.Width = this.Bounds.Width;
} }
} }
private static void ResetDrawerPosition(DrawerControlBase control, Size newSize)
{
if (control.Position == Position.Right)
{
control.Height = newSize.Height;
SetLeft(control, newSize.Width - control.Bounds.Width);
}
else if (control.Position == Position.Left)
{
control.Height = newSize.Height;
SetLeft(control, 0);
}
else if (control.Position == Position.Bottom)
{
control.Width = newSize.Width;
SetTop(control, 0);
}
else
{
control.Width = newSize.Width;
SetTop(control, newSize.Height-control.Bounds.Height);
}
}
private Animation CreateAnimation(Size elementBounds, Position position, bool appear = true) private Animation CreateAnimation(Size elementBounds, Position position, bool appear = true)
{ {

View File

@@ -130,6 +130,10 @@ public partial class OverlayDialogHost: Canvas
{ {
ResetDialogPosition(d, e.NewSize); ResetDialogPosition(d, e.NewSize);
} }
else if (_layers[i].Element is DrawerControlBase drawer)
{
ResetDrawerPosition(drawer, e.NewSize);
}
} }
} }