Add resize functionality and improve dialog controls

This commit introduces the ability to resize dialogs by adding `CanResize` properties to dialog options and control classes. It also refines dialog controls' behavior and layout, ensuring consistent resizing capabilities across different dialog types. Additionally, it enhances the overlay feedback element's positioning logic and updates the resizer's appearance and visibility handling.
This commit is contained in:
rabbitism
2024-09-17 22:44:35 +08:00
parent a70f7205e9
commit c512cb6e13
11 changed files with 278 additions and 168 deletions

View File

@@ -7,68 +7,72 @@
<ControlTheme x:Key="{x:Type u:OverlayDialogHost}" TargetType="u:OverlayDialogHost">
<Setter Property="OverlayMaskBrush" Value="{DynamicResource OverlayDialogMaskBrush}" />
</ControlTheme>
<ControlTheme x:Key="{x:Type u:CustomDialogControl}" TargetType="u:CustomDialogControl">
<Setter Property="MinWidth" Value="96" />
<Setter Property="MinHeight" Value="96" />
<Setter Property="CornerRadius" Value="{DynamicResource DialogCornerRadius}" />
<Setter Property="Transitions">
<Transitions>
<TransformOperationsTransition Duration="0.2" Property="RenderTransform"/>
<TransformOperationsTransition Property="RenderTransform" Duration="0.2" />
</Transitions>
</Setter>
<Setter Property="RenderTransform" Value="scale(1.0)"></Setter>
<Setter Property="RenderTransform" Value="scale(1.0)" />
<Setter Property="Template">
<ControlTemplate TargetType="u:CustomDialogControl">
<Border
Name="PART_Border"
Focusable="True"
Padding="0"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Classes="Shadow"
ClipToBounds="False"
CornerRadius="{TemplateBinding CornerRadius}"
IsHitTestVisible="True"
Theme="{DynamicResource CardBorder}">
<Border ClipToBounds="True" CornerRadius="{TemplateBinding CornerRadius}">
<Grid RowDefinitions="Auto, *">
<ContentPresenter
Name="PART_ContentPresenter"
Grid.Row="0"
Grid.RowSpan="2"
Content="{TemplateBinding Content}" />
<Grid Grid.Row="0" ColumnDefinitions="*, Auto">
<Panel
Name="{x:Static u:DialogControlBase.PART_TitleArea}"
Grid.Column="0"
Grid.ColumnSpan="2"
Background="Transparent" />
<Button
Name="{x:Static u:MessageBoxWindow.PART_CloseButton}"
Grid.Column="1"
Margin="0,24,24,0"
DockPanel.Dock="Right"
Theme="{DynamicResource OverlayCloseButton}" />
<Panel>
<Border
Name="PART_Border"
Padding="0"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
Classes="Shadow"
ClipToBounds="False"
CornerRadius="{TemplateBinding CornerRadius}"
Focusable="True"
IsHitTestVisible="True"
Theme="{DynamicResource CardBorder}">
<Border ClipToBounds="True" CornerRadius="{TemplateBinding CornerRadius}">
<Grid RowDefinitions="Auto, *">
<ContentPresenter
Name="PART_ContentPresenter"
Grid.Row="0"
Grid.RowSpan="2"
Content="{TemplateBinding Content}" />
<Grid Grid.Row="0" ColumnDefinitions="*, Auto">
<Panel
Name="{x:Static u:DialogControlBase.PART_TitleArea}"
Grid.Column="0"
Grid.ColumnSpan="2"
Background="Transparent" />
<Button
Name="{x:Static u:MessageBoxWindow.PART_CloseButton}"
Grid.Column="1"
Margin="0,24,24,0"
DockPanel.Dock="Right"
Theme="{DynamicResource OverlayCloseButton}" />
</Grid>
</Grid>
</Grid>
</Border>
</Border>
</Border>
<u:DialogResizer IsVisible="{TemplateBinding CanResize}" />
</Panel>
</ControlTemplate>
</Setter>
<Style Selector="^:full-screen">
<Setter Property="CornerRadius" Value="0"/>
<Setter Property="CornerRadius" Value="0" />
<Style Selector="^ /template/ Border#PART_Border">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Theme" Value="{x:Null}"/>
<Setter Property="Margin" Value="0"/>
<Setter Property="Background" Value="{DynamicResource BorderCardBackground}"></Setter>
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Theme" Value="{x:Null}" />
<Setter Property="Margin" Value="0" />
<Setter Property="Background" Value="{DynamicResource BorderCardBackground}" />
</Style>
</Style>
<Style Selector="^ /template/ Panel#PART_TitleArea">
<Setter Property="ContextFlyout">
<MenuFlyout>
<MenuItem
Command="{Binding $parent[u:DialogControlBase].Close}"
Header="{DynamicResource STRING_MENU_DIALOG_CLOSE}">
<MenuItem Command="{Binding $parent[u:DialogControlBase].Close}" Header="{DynamicResource STRING_MENU_DIALOG_CLOSE}">
<MenuItem.Icon>
<PathIcon
Width="12"
@@ -126,9 +130,7 @@
Data="{DynamicResource DialogArrangeSendToBackGlyph}" />
</MenuItem.Icon>
</MenuItem>
<MenuItem
Command="{Binding $parent[u:DialogControlBase].Close}"
Header="{DynamicResource STRING_MENU_DIALOG_CLOSE}">
<MenuItem Command="{Binding $parent[u:DialogControlBase].Close}" Header="{DynamicResource STRING_MENU_DIALOG_CLOSE}">
<MenuItem.Icon>
<PathIcon
Width="12"
@@ -142,112 +144,117 @@
</ControlTheme>
<ControlTheme x:Key="{x:Type u:DefaultDialogControl}" TargetType="u:DefaultDialogControl">
<Setter Property="MinWidth" Value="96" />
<Setter Property="MinHeight" Value="96" />
<Setter Property="CornerRadius" Value="{DynamicResource DialogCornerRadius}" />
<Setter Property="Transitions">
<Transitions>
<TransformOperationsTransition Duration="0.2" Property="RenderTransform"/>
<TransformOperationsTransition Property="RenderTransform" Duration="0.2" />
</Transitions>
</Setter>
<Setter Property="Template">
<ControlTemplate TargetType="u:DefaultDialogControl">
<Border
Name="PART_Border"
Padding="0"
Focusable="True"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
BoxShadow="0 0 8 0 #1A000000"
Classes="Shadow"
ClipToBounds="False"
CornerRadius="{TemplateBinding CornerRadius}"
IsHitTestVisible="True"
Theme="{DynamicResource CardBorder}">
<Border ClipToBounds="True" CornerRadius="{TemplateBinding CornerRadius}">
<Grid RowDefinitions="Auto, *, Auto">
<ScrollViewer Grid.Row="1">
<ContentPresenter
Name="PART_ContentPresenter"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Margin="24,8"
Content="{TemplateBinding Content}" />
</ScrollViewer>
<Grid Grid.Row="0" ColumnDefinitions="Auto, *, Auto">
<Panel
Name="{x:Static u:DialogControlBase.PART_TitleArea}"
Grid.Column="0"
Grid.ColumnSpan="3"
Background="Transparent" />
<PathIcon
Name="PART_Icon"
Grid.Column="0"
Width="16"
Height="16"
Margin="24,24,8,0"
VerticalAlignment="Center" />
<TextBlock
Name="PART_Title"
Grid.Column="1"
Margin="0,24,0,0"
VerticalAlignment="Center"
FontSize="16"
FontWeight="{DynamicResource TextBlockTitleFontWeight}"
IsHitTestVisible="False"
IsVisible="{TemplateBinding Title,
Converter={x:Static ObjectConverters.IsNotNull}}"
Text="{TemplateBinding Title}"
TextWrapping="Wrap" />
<Button
Name="{x:Static u:MessageBoxWindow.PART_CloseButton}"
Grid.Column="2"
Margin="0,24,24,0"
DockPanel.Dock="Right"
Theme="{DynamicResource OverlayCloseButton}" />
<Panel>
<Border
Name="PART_Border"
Padding="0"
HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
VerticalAlignment="{TemplateBinding VerticalAlignment}"
BoxShadow="0 0 8 0 #1A000000"
Classes="Shadow"
ClipToBounds="False"
CornerRadius="{TemplateBinding CornerRadius}"
Focusable="True"
IsHitTestVisible="True"
Theme="{DynamicResource CardBorder}">
<Border ClipToBounds="True" CornerRadius="{TemplateBinding CornerRadius}">
<Grid RowDefinitions="Auto, *, Auto">
<ScrollViewer Grid.Row="1">
<ContentPresenter
Name="PART_ContentPresenter"
Margin="24,8"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Content="{TemplateBinding Content}" />
</ScrollViewer>
<Grid Grid.Row="0" ColumnDefinitions="Auto, *, Auto">
<Panel
Name="{x:Static u:DialogControlBase.PART_TitleArea}"
Grid.Column="0"
Grid.ColumnSpan="3"
Background="Transparent" />
<PathIcon
Name="PART_Icon"
Grid.Column="0"
Width="16"
Height="16"
Margin="24,24,8,0"
VerticalAlignment="Center" />
<TextBlock
Name="PART_Title"
Grid.Column="1"
Margin="0,24,0,0"
VerticalAlignment="Center"
FontSize="16"
FontWeight="{DynamicResource TextBlockTitleFontWeight}"
IsHitTestVisible="False"
IsVisible="{TemplateBinding Title,
Converter={x:Static ObjectConverters.IsNotNull}}"
Text="{TemplateBinding Title}"
TextWrapping="Wrap" />
<Button
Name="{x:Static u:MessageBoxWindow.PART_CloseButton}"
Grid.Column="2"
Margin="0,24,24,0"
DockPanel.Dock="Right"
Theme="{DynamicResource OverlayCloseButton}" />
</Grid>
<StackPanel
Grid.Row="2"
Margin="24,0,24,24"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button
Name="{x:Static u:DefaultDialogControl.PART_CancelButton}"
Margin="8,0,0,0"
Classes="Tertiary"
Content="{DynamicResource STRING_MENU_DIALOG_CANCEL}" />
<Button
Name="{x:Static u:DefaultDialogControl.PART_NoButton}"
Margin="8,0,0,0"
Classes="Danger"
Content="{DynamicResource STRING_MENU_DIALOG_NO}"
Theme="{DynamicResource SolidButton}" />
<Button
Name="{x:Static u:DefaultDialogControl.PART_YesButton}"
Margin="8,0,0,0"
Classes="Primary"
Content="{DynamicResource STRING_MENU_DIALOG_YES}"
Theme="{DynamicResource SolidButton}" />
<Button
Name="{x:Static u:DefaultDialogControl.PART_OKButton}"
Margin="8,0,0,0"
Classes="Primary"
Content="{DynamicResource STRING_MENU_DIALOG_OK}"
Theme="{DynamicResource SolidButton}" />
</StackPanel>
</Grid>
<StackPanel
Grid.Row="2"
Margin="24,0,24,24"
HorizontalAlignment="Right"
Orientation="Horizontal">
<Button
Name="{x:Static u:DefaultDialogControl.PART_CancelButton}"
Margin="8,0,0,0"
Classes="Tertiary"
Content="{DynamicResource STRING_MENU_DIALOG_CANCEL}" />
<Button
Name="{x:Static u:DefaultDialogControl.PART_NoButton}"
Margin="8,0,0,0"
Classes="Danger"
Content="{DynamicResource STRING_MENU_DIALOG_NO}"
Theme="{DynamicResource SolidButton}" />
<Button
Name="{x:Static u:DefaultDialogControl.PART_YesButton}"
Margin="8,0,0,0"
Classes="Primary"
Content="{DynamicResource STRING_MENU_DIALOG_YES}"
Theme="{DynamicResource SolidButton}" />
<Button
Name="{x:Static u:DefaultDialogControl.PART_OKButton}"
Margin="8,0,0,0"
Classes="Primary"
Content="{DynamicResource STRING_MENU_DIALOG_OK}"
Theme="{DynamicResource SolidButton}" />
</StackPanel>
<u:DialogResizer Grid.Row="0" Grid.RowSpan="3"/>
</Grid>
</Border>
</Border>
</Border>
<u:DialogResizer IsVisible="{TemplateBinding CanResize}"/>
</Panel>
</ControlTemplate>
</Setter>
<Style Selector="^:full-screen">
<Setter Property="CornerRadius" Value="0"/>
<Setter Property="CornerRadius" Value="0" />
</Style>
<Style Selector="^:full-screen /template/ Border#PART_Border">
<Setter Property="HorizontalAlignment" Value="Stretch"/>
<Setter Property="VerticalAlignment" Value="Stretch"/>
<Setter Property="Theme" Value="{x:Null}"/>
<Setter Property="Margin" Value="0"></Setter>
<Setter Property="Background" Value="{DynamicResource BorderCardBackground}"></Setter>
<Setter Property="HorizontalAlignment" Value="Stretch" />
<Setter Property="VerticalAlignment" Value="Stretch" />
<Setter Property="Theme" Value="{x:Null}" />
<Setter Property="Margin" Value="0" />
<Setter Property="Background" Value="{DynamicResource BorderCardBackground}" />
</Style>
<Style Selector="^[Mode=None]">
<Style Selector="^ /template/ PathIcon#PART_Icon">
@@ -370,9 +377,7 @@
<Style Selector="^ /template/ Panel#PART_TitleArea">
<Setter Property="ContextFlyout">
<MenuFlyout>
<MenuItem
Command="{Binding $parent[u:DialogControlBase].Close}"
Header="{DynamicResource STRING_MENU_DIALOG_CLOSE}">
<MenuItem Command="{Binding $parent[u:DialogControlBase].Close}" Header="{DynamicResource STRING_MENU_DIALOG_CLOSE}">
<MenuItem.Icon>
<PathIcon
Width="12"
@@ -474,11 +479,12 @@
<ControlTemplate TargetType="u:DialogWindow">
<Panel>
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
<Border Background="{TemplateBinding Background}"
BackgroundSizing="InnerBorderEdge"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
IsHitTestVisible="False" />
<Border
Background="{TemplateBinding Background}"
BackgroundSizing="InnerBorderEdge"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
IsHitTestVisible="False" />
<Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" />
<VisualLayerManager>
<Grid RowDefinitions="Auto, *">
@@ -506,6 +512,10 @@
Margin="0,24,24,0"
Theme="{DynamicResource CloseButton}" />
</Grid>
<u:WindowResizer
Grid.Row="0"
Grid.RowSpan="2"
IsVisible="{TemplateBinding IsManagedResizerVisible}" />
</Grid>
</VisualLayerManager>
</Panel>
@@ -541,11 +551,12 @@
<ControlTemplate TargetType="u:DefaultDialogWindow">
<Panel>
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
<Border Background="{TemplateBinding Background}"
BackgroundSizing="InnerBorderEdge"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
IsHitTestVisible="False" />
<Border
Background="{TemplateBinding Background}"
BackgroundSizing="InnerBorderEdge"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
IsHitTestVisible="False" />
<Panel Margin="{TemplateBinding WindowDecorationMargin}" Background="Transparent" />
<VisualLayerManager>
<Grid RowDefinitions="Auto, *, Auto">
@@ -615,6 +626,10 @@
Content="{DynamicResource STRING_MENU_DIALOG_OK}"
Theme="{DynamicResource SolidButton}" />
</StackPanel>
<u:WindowResizer
Grid.Row="0"
Grid.RowSpan="3"
IsVisible="{TemplateBinding IsManagedResizerVisible}" />
</Grid>
</VisualLayerManager>
</Panel>
@@ -739,4 +754,4 @@
</Style>
</Style>
</ControlTheme>
</ResourceDictionary>
</ResourceDictionary>

View File

@@ -13,10 +13,12 @@
</ControlTheme>
<ControlTheme TargetType="u:DialogResizerThumb" x:Key="{x:Type u:DialogResizerThumb}">
<Setter Property="Background" Value="Red" />
<Setter Property="Background" Value="Transparent" />
<Setter Property="Template">
<ControlTemplate TargetType="u:DialogResizerThumb">
<iri:PureRectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{TemplateBinding Background}"/>
<Panel>
<iri:PureRectangle HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="{TemplateBinding Background}"/>
</Panel>
</ControlTemplate>
</Setter>
</ControlTheme>

View File

@@ -205,6 +205,8 @@ public static class Dialog
window.IsCloseButtonVisible = options.IsCloseButtonVisible;
window.ShowInTaskbar = options.ShowInTaskBar;
window.CanDragMove = options.CanDragMove;
window.CanResize = options.CanResize;
window.IsManagedResizerVisible = options.CanResize;
if (options.StartupLocation == WindowStartupLocation.Manual)
{
if (options.Position is not null)
@@ -229,6 +231,8 @@ public static class Dialog
window.ShowInTaskbar = options.ShowInTaskBar;
window.IsCloseButtonVisible = options.IsCloseButtonVisible;
window.CanDragMove = options.CanDragMove;
window.IsManagedResizerVisible = options.CanResize;
window.CanResize = options.CanResize;
if (options.StartupLocation == WindowStartupLocation.Manual)
{
if (options.Position is not null)

View File

@@ -24,6 +24,9 @@ public abstract class DialogControlBase : OverlayFeedbackElement
AvaloniaProperty.RegisterDirect<DialogControlBase, bool>(
nameof(IsFullScreen), o => o.IsFullScreen, (o, v) => o.IsFullScreen = v);
public static readonly StyledProperty<bool> CanResizeProperty = AvaloniaProperty.Register<DialogControlBase, bool>(
nameof(CanResize));
protected internal Button? _closeButton;
private bool _isFullScreen;
@@ -36,6 +39,12 @@ public abstract class DialogControlBase : OverlayFeedbackElement
IsFullScreenProperty.AffectsPseudoClass<DialogControlBase>(PC_FullScreen);
}
public bool CanResize
{
get => GetValue(CanResizeProperty);
set => SetValue(CanResizeProperty, value);
}
internal HorizontalPosition HorizontalAnchor { get; set; } = HorizontalPosition.Center;
internal VerticalPosition VerticalAnchor { get; set; } = VerticalPosition.Center;
internal HorizontalPosition ActualHorizontalAnchor { get; set; }

View File

@@ -17,8 +17,17 @@ public class DialogWindow : Window
public const string PART_TitleArea = "PART_TitleArea";
protected internal Button? _closeButton;
private Panel? _titleArea;
public bool CanDragMove { get; set; } = true;
public static readonly StyledProperty<bool> IsManagedResizerVisibleProperty = AvaloniaProperty.Register<DialogWindow, bool>(
nameof(IsManagedResizerVisible));
public bool IsManagedResizerVisible
{
get => GetValue(IsManagedResizerVisibleProperty);
set => SetValue(IsManagedResizerVisibleProperty, value);
}
static DialogWindow()
{
@@ -26,9 +35,11 @@ public class DialogWindow : Window
window.OnDataContextChange(e));
}
public bool CanDragMove { get; set; } = true;
internal bool? IsCloseButtonVisible { get; set; }
protected override Type StyleKeyOverride { get; } = typeof(DialogWindow);
internal bool? IsCloseButtonVisible { get; set; }
private void OnDataContextChange(AvaloniaPropertyChangedEventArgs<object?> args)
{

View File

@@ -30,4 +30,6 @@ public class DialogOptions
public bool ShowInTaskBar { get; set; } = true;
public bool CanDragMove { get; set; } = true;
public bool CanResize { get; set; }
}

View File

@@ -62,4 +62,6 @@ public class OverlayDialogOptions
/// id.
/// </summary>
public int? TopLevelHashCode { get; set; }
public bool CanResize { get; set; }
}

View File

@@ -204,6 +204,7 @@ public static class OverlayDialog
options.VerticalAnchor == VerticalPosition.Center ? null : options.VerticalOffset;
control.IsCloseButtonVisible = options.IsCloseButtonVisible;
control.CanLightDismiss = options.CanLightDismiss;
control.CanResize = options.CanResize;
DialogControlBase.SetCanDragMove(control, options.CanDragMove);
}
@@ -229,6 +230,7 @@ public static class OverlayDialog
control.Title = options.Title;
control.CanLightDismiss = options.CanLightDismiss;
control.IsCloseButtonVisible = options.IsCloseButtonVisible;
control.CanResize = options.CanResize;
DialogControlBase.SetCanDragMove(control, options.CanDragMove);
}

View File

@@ -149,10 +149,14 @@ public abstract class OverlayFeedbackElement : ContentControl
{
if (containerBounds is not null)
{
var minX = -left;
var minY = -top;
var maxX = containerBounds.Value.Width - left - width;
var maxY = containerBounds.Value.Height - top - height;
var minX = windowEdge is WindowEdge.West or WindowEdge.NorthWest or WindowEdge.SouthWest
? -left
: double.NegativeInfinity;
var minY = windowEdge is WindowEdge.North or WindowEdge.NorthEast or WindowEdge.NorthWest
? -top
: double.NegativeInfinity;
var maxX = containerBounds.Value.Width - left - MinWidth;
var maxY = containerBounds.Value.Height - top - MinHeight;
diff = new Point(MathHelpers.SafeClamp(diff.X, minX, maxX), MathHelpers.SafeClamp(diff.Y, minY, maxY));
}
switch (windowEdge)

View File

@@ -1,10 +1,30 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
using Irihi.Avalonia.Shared.Helpers;
namespace Ursa.Controls;
public class DialogResizer: TemplatedControl
{
public const string PART_Top = "PART_Top";
public const string PART_Bottom = "PART_Bottom";
public const string PART_Left = "PART_Left";
public const string PART_Right = "PART_Right";
public const string PART_TopLeft = "PART_TopLeft";
public const string PART_TopRight = "PART_TopRight";
public const string PART_BottomLeft = "PART_BottomLeft";
public const string PART_BottomRight = "PART_BottomRight";
private Thumb? _top;
private Thumb? _bottom;
private Thumb? _left;
private Thumb? _right;
private Thumb? _topLeft;
private Thumb? _topRight;
private Thumb? _bottomLeft;
private Thumb? _bottomRight;
public static readonly StyledProperty<ResizeDirection> ResizeDirectionProperty = AvaloniaProperty.Register<DialogResizer, ResizeDirection>(
nameof(ResizeDirection));
@@ -16,4 +36,39 @@ public class DialogResizer: TemplatedControl
get => GetValue(ResizeDirectionProperty);
set => SetValue(ResizeDirectionProperty, value);
}
static DialogResizer()
{
ResizeDirectionProperty.Changed.AddClassHandler<DialogResizer, ResizeDirection>((resizer, e) => resizer.OnResizeDirectionChanged(e));
}
private void OnResizeDirectionChanged(AvaloniaPropertyChangedEventArgs<ResizeDirection> args)
{
UpdateThumbVisibility(args.NewValue.Value);
}
protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
{
base.OnApplyTemplate(e);
_top = e.NameScope.Find<Thumb>(PART_Top);
_bottom = e.NameScope.Find<Thumb>(PART_Bottom);
_left = e.NameScope.Find<Thumb>(PART_Left);
_right = e.NameScope.Find<Thumb>(PART_Right);
_topLeft = e.NameScope.Find<Thumb>(PART_TopLeft);
_topRight = e.NameScope.Find<Thumb>(PART_TopRight);
_bottomLeft = e.NameScope.Find<Thumb>(PART_BottomLeft);
_bottomRight = e.NameScope.Find<Thumb>(PART_BottomRight);
}
private void UpdateThumbVisibility(ResizeDirection direction)
{
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.Top), _top);
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.Bottom), _bottom);
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.Left), _left);
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.Right), _right);
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.TopLeft), _topLeft);
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.TopRight), _topRight);
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.BottomLeft), _bottomLeft);
IsVisibleProperty.SetValue(direction.HasFlag(ResizeDirection.BottomRight), _bottomRight);
}
}

View File

@@ -3,12 +3,16 @@ namespace Ursa.Controls;
[Flags]
public enum ResizeDirection
{
Top,
Bottom,
Left,
Right,
TopLeft,
TopRight,
BottomLeft,
BottomRight,
Top = 1,
Bottom = 2,
Left = 4,
Right = 8,
TopLeft = 16,
TopRight = 32,
BottomLeft = 64,
BottomRight = 128,
Sides = Top | Bottom | Left | Right,
Corners = TopLeft | TopRight | BottomLeft | BottomRight,
All = Sides | Corners,
}