feat: implement resizing logic.
This commit is contained in:
@@ -1,25 +1,43 @@
|
||||
<UserControl xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:local="clr-namespace:Ursa.Demo.Dialogs"
|
||||
x:DataType="local:DialogWithActionViewModel"
|
||||
x:CompileBindings="True"
|
||||
Background="{DynamicResource SemiYellow1}"
|
||||
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
|
||||
x:Class="Ursa.Demo.Dialogs.DialogWithAction">
|
||||
<StackPanel Margin="24">
|
||||
<TextBlock FontSize="16" FontWeight="600" Margin="8" Text="{Binding Title}"></TextBlock>
|
||||
<Calendar SelectedDate="{Binding Date}" ></Calendar>
|
||||
<StackPanel HorizontalAlignment="Right" Orientation="Horizontal" Spacing="8">
|
||||
<Button Content="Dialog" Command="{Binding DialogCommand}"></Button>
|
||||
<Button Content="OK" Command="{Binding OKCommand}"></Button>
|
||||
<Button Content="Cancel" Command="{Binding CancelCommand}"></Button>
|
||||
<UserControl
|
||||
x:Class="Ursa.Demo.Dialogs.DialogWithAction"
|
||||
xmlns="https://github.com/avaloniaui"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Ursa.Demo.Dialogs"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
d:DesignHeight="450"
|
||||
d:DesignWidth="800"
|
||||
x:CompileBindings="True"
|
||||
x:DataType="local:DialogWithActionViewModel"
|
||||
Background="{DynamicResource SemiYellow1}"
|
||||
mc:Ignorable="d">
|
||||
<Grid Margin="24" RowDefinitions="Auto, *, Auto">
|
||||
<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>
|
||||
<ComboBoxItem>A</ComboBoxItem>
|
||||
<ComboBoxItem>B</ComboBoxItem>
|
||||
<ComboBoxItem>C</ComboBoxItem>
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
|
||||
@@ -6,6 +6,7 @@ using CommunityToolkit.Mvvm.Input;
|
||||
using Ursa.Common;
|
||||
using Ursa.Controls;
|
||||
using Ursa.Controls.Options;
|
||||
using Ursa.Demo.Dialogs;
|
||||
|
||||
namespace Ursa.Demo.ViewModels;
|
||||
|
||||
@@ -23,6 +24,7 @@ public partial class DrawerDemoViewModel: ObservableObject
|
||||
|
||||
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});
|
||||
}
|
||||
}
|
||||
@@ -135,6 +135,11 @@
|
||||
|
||||
<ControlTheme x:Key="{x:Type u:DefaultDialogControl}" TargetType="u:DefaultDialogControl">
|
||||
<Setter Property="CornerRadius" Value="12" />
|
||||
<Setter Property="Transitions">
|
||||
<Transitions>
|
||||
<TransformOperationsTransition Duration="0.2" Property="RenderTransform"/>
|
||||
</Transitions>
|
||||
</Setter>
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:DefaultDialogControl">
|
||||
<Border
|
||||
@@ -223,6 +228,9 @@
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</Setter>
|
||||
<Style Selector="^[IsClosed=True]">
|
||||
<Setter Property="RenderTransform" Value="scale(0.95)"/>
|
||||
</Style>
|
||||
<Style Selector="^[Mode=None]">
|
||||
<Style Selector="^ /template/ PathIcon#PART_Icon">
|
||||
<Setter Property="IsVisible" Value="False" />
|
||||
|
||||
@@ -6,7 +6,8 @@
|
||||
<Setter Property="HorizontalAlignment" Value="Stretch"></Setter>
|
||||
<Setter Property="Template">
|
||||
<ControlTemplate TargetType="u:CustomDrawerControl">
|
||||
<Border Margin="8 -1 -1 -1"
|
||||
<Border Name="PART_Root"
|
||||
Margin="8 -1 -1 -1"
|
||||
Padding="0"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
@@ -41,5 +42,25 @@
|
||||
</Border>
|
||||
</ControlTemplate>
|
||||
</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>
|
||||
</ResourceDictionary>
|
||||
|
||||
@@ -46,6 +46,30 @@ public partial class OverlayDialogHost
|
||||
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)
|
||||
{
|
||||
|
||||
@@ -130,6 +130,10 @@ public partial class OverlayDialogHost: Canvas
|
||||
{
|
||||
ResetDialogPosition(d, e.NewSize);
|
||||
}
|
||||
else if (_layers[i].Element is DrawerControlBase drawer)
|
||||
{
|
||||
ResetDrawerPosition(drawer, e.NewSize);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user