mirror of
https://gitcode.com/gh_mirrors/se/Semi.Avalonia
synced 2026-04-25 02:46:36 +08:00
feat:popup animation.
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
<!-- You can still reference in old way. -->
|
<!-- You can still reference in old way. -->
|
||||||
<!-- <StyleInclude Source="avares://Semi.Avalonia/Themes/Index.axaml" /> -->
|
<!-- <StyleInclude Source="avares://Semi.Avalonia/Themes/Index.axaml" /> -->
|
||||||
<semi:SemiTheme Locale="zh-cn" />
|
<semi:SemiTheme Locale="zh-cn" />
|
||||||
|
<semi:PopupAnimations/>
|
||||||
<StyleInclude Source="avares://Semi.Avalonia.DataGrid/Index.axaml" />
|
<StyleInclude Source="avares://Semi.Avalonia.DataGrid/Index.axaml" />
|
||||||
<StyleInclude Source="avares://Semi.Avalonia.ColorPicker/Index.axaml" />
|
<StyleInclude Source="avares://Semi.Avalonia.ColorPicker/Index.axaml" />
|
||||||
</Application.Styles>
|
</Application.Styles>
|
||||||
|
|||||||
47
src/Semi.Avalonia/Animations/PopupAnimations.axaml
Normal file
47
src/Semi.Avalonia/Animations/PopupAnimations.axaml
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
<Styles xmlns="https://github.com/avaloniaui"
|
||||||
|
x:Class="Semi.Avalonia.PopupAnimations"
|
||||||
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||||
|
xmlns:converters="clr-namespace:Semi.Avalonia.Converters">
|
||||||
|
<Design.PreviewWith>
|
||||||
|
<Border Padding="20">
|
||||||
|
<!-- Add Controls for Previewer Here -->
|
||||||
|
</Border>
|
||||||
|
</Design.PreviewWith>
|
||||||
|
|
||||||
|
<!-- Add Styles Here -->
|
||||||
|
<Style Selector="Popup LayoutTransformControl#PART_LayoutTransform">
|
||||||
|
<Setter Property="RenderTransformOrigin" Value="{Binding $parent[Popup].Placement, Converter={x:Static converters:PlacementToRenderTransformOriginConverter.Instance}}"></Setter>
|
||||||
|
</Style>
|
||||||
|
<Style Selector="Flyout LayoutTransformControl#PART_LayoutTransform">
|
||||||
|
<Setter Property="RenderTransformOrigin" Value="{Binding $parent[Flyout].Placement, Converter={x:Static converters:PlacementToRenderTransformOriginConverter.Instance}}"></Setter>
|
||||||
|
</Style>
|
||||||
|
|
||||||
|
<Style Selector="Popup[IsOpen=True] LayoutTransformControl#PART_LayoutTransform">
|
||||||
|
<Style.Animations>
|
||||||
|
<Animation Duration="0:0:0.2" FillMode="Forward">
|
||||||
|
<KeyFrame Cue="0.0">
|
||||||
|
<Setter Property="ScaleTransform.ScaleX" Value="0.95"/>
|
||||||
|
<Setter Property="ScaleTransform.ScaleY" Value="0.95"/>
|
||||||
|
</KeyFrame>
|
||||||
|
<KeyFrame Cue="1.0">
|
||||||
|
<Setter Property="ScaleTransform.ScaleX" Value="1.0"/>
|
||||||
|
<Setter Property="ScaleTransform.ScaleY" Value="1.0"/>
|
||||||
|
</KeyFrame>
|
||||||
|
</Animation>
|
||||||
|
</Style.Animations>
|
||||||
|
</Style>
|
||||||
|
<Style Selector="Popup[IsOpen=False] LayoutTransformControl#PART_LayoutTransform">
|
||||||
|
<Style.Animations>
|
||||||
|
<Animation Duration="0:0:0.2" FillMode="Forward">
|
||||||
|
<KeyFrame Cue="0.0">
|
||||||
|
<Setter Property="ScaleTransform.ScaleX" Value="0.95"/>
|
||||||
|
<Setter Property="ScaleTransform.ScaleY" Value="0.95"/>
|
||||||
|
</KeyFrame>
|
||||||
|
<KeyFrame Cue="1.0">
|
||||||
|
<Setter Property="ScaleTransform.ScaleX" Value="1.0"/>
|
||||||
|
<Setter Property="ScaleTransform.ScaleY" Value="1.0"/>
|
||||||
|
</KeyFrame>
|
||||||
|
</Animation>
|
||||||
|
</Style.Animations>
|
||||||
|
</Style>
|
||||||
|
</Styles>
|
||||||
8
src/Semi.Avalonia/Animations/PopupAnimations.axaml.cs
Normal file
8
src/Semi.Avalonia/Animations/PopupAnimations.axaml.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using Avalonia.Styling;
|
||||||
|
|
||||||
|
namespace Semi.Avalonia;
|
||||||
|
|
||||||
|
public class PopupAnimations: Styles
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,12 +11,14 @@
|
|||||||
<Panel>
|
<Panel>
|
||||||
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
|
<Border Name="PART_TransparencyFallback" IsHitTestVisible="False" />
|
||||||
<VisualLayerManager IsPopup="True">
|
<VisualLayerManager IsPopup="True">
|
||||||
<ContentPresenter
|
<LayoutTransformControl Name="PART_LayoutTransform">
|
||||||
Name="PART_ContentPresenter"
|
<ContentPresenter
|
||||||
Padding="{TemplateBinding Padding}"
|
Name="PART_ContentPresenter"
|
||||||
Background="{TemplateBinding Background}"
|
Padding="{TemplateBinding Padding}"
|
||||||
Content="{TemplateBinding Content}"
|
Background="{TemplateBinding Background}"
|
||||||
ContentTemplate="{TemplateBinding ContentTemplate}" />
|
Content="{TemplateBinding Content}"
|
||||||
|
ContentTemplate="{TemplateBinding ContentTemplate}" />
|
||||||
|
</LayoutTransformControl>
|
||||||
</VisualLayerManager>
|
</VisualLayerManager>
|
||||||
</Panel>
|
</Panel>
|
||||||
</LayoutTransformControl>
|
</LayoutTransformControl>
|
||||||
|
|||||||
@@ -0,0 +1,57 @@
|
|||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using Avalonia;
|
||||||
|
using Avalonia.Controls;
|
||||||
|
using Avalonia.Data.Converters;
|
||||||
|
|
||||||
|
namespace Semi.Avalonia.Converters;
|
||||||
|
|
||||||
|
public class PlacementToRenderTransformOriginConverter: IValueConverter
|
||||||
|
{
|
||||||
|
public static PlacementToRenderTransformOriginConverter Instance { get; } = new PlacementToRenderTransformOriginConverter();
|
||||||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
if (value is not PlacementMode p)
|
||||||
|
{
|
||||||
|
return new RelativePoint(0.5, 0.5, RelativeUnit.Relative);
|
||||||
|
}
|
||||||
|
switch (p)
|
||||||
|
{
|
||||||
|
case PlacementMode.Bottom:
|
||||||
|
return new RelativePoint(0.5, 0.0, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.Left:
|
||||||
|
return new RelativePoint(1.0, 0.5, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.Right:
|
||||||
|
return new RelativePoint(0.0, 0.5, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.Top:
|
||||||
|
return new RelativePoint(0.5, 1.0, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.Pointer:
|
||||||
|
return new RelativePoint(0.0, 0.0, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.Center:
|
||||||
|
case PlacementMode.AnchorAndGravity:
|
||||||
|
return new RelativePoint(0.5, 0.5, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.BottomEdgeAlignedLeft:
|
||||||
|
return new RelativePoint(0.0, 0.0, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.BottomEdgeAlignedRight:
|
||||||
|
return new RelativePoint(1.0, 0.0, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.LeftEdgeAlignedTop:
|
||||||
|
return new RelativePoint(1.0, 1.0, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.LeftEdgeAlignedBottom:
|
||||||
|
return new RelativePoint(1.0, 0.0, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.RightEdgeAlignedTop:
|
||||||
|
return new RelativePoint(0.0, 1.0, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.RightEdgeAlignedBottom:
|
||||||
|
return new RelativePoint(0.0, 0.0, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.TopEdgeAlignedLeft:
|
||||||
|
return new RelativePoint(0.0, 1.0, RelativeUnit.Relative);
|
||||||
|
case PlacementMode.TopEdgeAlignedRight:
|
||||||
|
return new RelativePoint(1.0, 1.0, RelativeUnit.Relative);
|
||||||
|
}
|
||||||
|
return new RelativePoint(0.5, 0.5, RelativeUnit.Relative);
|
||||||
|
}
|
||||||
|
|
||||||
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user