mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-16 21:21:03 +08:00
Refactor ApplyTemplate
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 219 KiB After Width: | Height: | Size: 233 KiB |
@@ -52,25 +52,20 @@ internal class DotBadgeIndicator : Control,
|
||||
AffectsRender<DotBadgeIndicator>(BadgeDotColorProperty, BadgeShadowSizeProperty);
|
||||
}
|
||||
|
||||
public sealed override void ApplyTemplate()
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.ApplyTemplate();
|
||||
BuildBoxShadow();
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
base.OnAttachedToVisualTree(e);
|
||||
_resourceBindingsDisposable = new CompositeDisposable();
|
||||
this.AddResourceBindingDisposable(
|
||||
TokenResourceBinder.CreateTokenBinding(this, BadgeShadowSizeProperty, BadgeTokenKey.BadgeShadowSize));
|
||||
this.AddResourceBindingDisposable(TokenResourceBinder.CreateTokenBinding(this, BadgeShadowColorProperty,
|
||||
BadgeTokenKey.BadgeShadowColor));
|
||||
BuildBoxShadow();
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnDetachedFromLogicalTree(e);
|
||||
base.OnDetachedFromVisualTree(e);
|
||||
this.DisposeTokenBindings();
|
||||
}
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ internal class RibbonBadgeAdorner : Control
|
||||
|
||||
private void BuildStyles()
|
||||
{
|
||||
// TODO 需要优化
|
||||
var commonStyle = new Style(selector => selector.OfType<RibbonBadgeAdorner>());
|
||||
commonStyle.Add(RibbonColorProperty, SharedTokenKey.ColorPrimary);
|
||||
commonStyle.Add(CornerRadiusProperty, SharedTokenKey.BorderRadiusSM);
|
||||
|
||||
@@ -179,21 +179,10 @@ public class FlyoutHost : Control,
|
||||
this.BindMotionProperties();
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
_resourceBindingsDisposable = new CompositeDisposable();
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnDetachedFromLogicalTree(e);
|
||||
this.DisposeTokenBindings();
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
_resourceBindingsDisposable = new CompositeDisposable();
|
||||
BindUtils.RelayBind(this, AnchorTargetProperty, _flyoutStateHelper, FlyoutStateHelper.AnchorTargetProperty);
|
||||
BindUtils.RelayBind(this, FlyoutProperty, _flyoutStateHelper, FlyoutStateHelper.FlyoutProperty);
|
||||
BindUtils.RelayBind(this, MouseEnterDelayProperty, _flyoutStateHelper,
|
||||
@@ -210,6 +199,7 @@ public class FlyoutHost : Control,
|
||||
{
|
||||
base.OnDetachedFromVisualTree(e);
|
||||
_flyoutStateHelper.NotifyDetachedFromVisualTree();
|
||||
this.DisposeTokenBindings();
|
||||
}
|
||||
|
||||
protected virtual void SetupFlyoutProperties()
|
||||
|
||||
@@ -79,6 +79,7 @@ public class MarqueeLabel : TextBlock,
|
||||
public MarqueeLabel()
|
||||
{
|
||||
this.RegisterResources();
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
@@ -134,7 +135,7 @@ public class MarqueeLabel : TextBlock,
|
||||
{
|
||||
base.ApplyTemplate();
|
||||
// 为了强制
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
|
||||
}
|
||||
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Reactive.Disposables;
|
||||
using AtomUI.Controls.PopupConfirmLang;
|
||||
using AtomUI.Controls.PopupConfirmLang;
|
||||
using AtomUI.IconPkg;
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Theme.Data;
|
||||
@@ -8,7 +7,6 @@ using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
using Avalonia.Controls.Templates;
|
||||
using Avalonia.Interactivity;
|
||||
using Avalonia.LogicalTree;
|
||||
|
||||
namespace AtomUI.Controls;
|
||||
|
||||
@@ -20,8 +18,7 @@ public enum PopupConfirmStatus
|
||||
}
|
||||
|
||||
public class PopupConfirm : FlyoutHost,
|
||||
IControlSharedTokenResourcesHost,
|
||||
IResourceBindingManager
|
||||
IControlSharedTokenResourcesHost
|
||||
{
|
||||
#region 公共属性属性
|
||||
|
||||
@@ -140,37 +137,21 @@ public class PopupConfirm : FlyoutHost,
|
||||
|
||||
Control IControlSharedTokenResourcesHost.HostControl => this;
|
||||
string IControlSharedTokenResourcesHost.TokenId => PopupConfirmToken.ID;
|
||||
CompositeDisposable? IResourceBindingManager.ResourceBindingsDisposable => _resourceBindingsDisposable;
|
||||
|
||||
#endregion
|
||||
|
||||
private CompositeDisposable? _resourceBindingsDisposable;
|
||||
|
||||
public PopupConfirm()
|
||||
{
|
||||
this.RegisterResources();
|
||||
}
|
||||
|
||||
public sealed override void ApplyTemplate()
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
Flyout ??= new PopupConfirmFlyout(this);
|
||||
base.OnAttachedToVisualTree(e);
|
||||
Flyout ??= new PopupConfirmFlyout(this);
|
||||
this.AddResourceBindingDisposable(LanguageResourceBinder.CreateBinding(this, OkTextProperty, PopupConfirmLangResourceKey.OkText));
|
||||
this.AddResourceBindingDisposable(LanguageResourceBinder.CreateBinding(this, CancelTextProperty, PopupConfirmLangResourceKey.CancelText));
|
||||
base.ApplyTemplate();
|
||||
}
|
||||
|
||||
protected override void OnAttachedToLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToLogicalTree(e);
|
||||
_resourceBindingsDisposable = new CompositeDisposable();
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnDetachedFromLogicalTree(e);
|
||||
this.DisposeTokenBindings();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public class PopupConfirmClickEventArgs : RoutedEventArgs
|
||||
|
||||
@@ -52,9 +52,16 @@ internal class ShadowRenderer : Control
|
||||
MaskContentBackgroundProperty.OverrideDefaultValue<ShadowRenderer>(new SolidColorBrush(Colors.Transparent));
|
||||
}
|
||||
|
||||
public sealed override void ApplyTemplate()
|
||||
public ShadowRenderer()
|
||||
{
|
||||
base.ApplyTemplate();
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
VerticalAlignment = VerticalAlignment.Stretch;
|
||||
IsHitTestVisible = false;
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
if (_layout is not null)
|
||||
{
|
||||
return;
|
||||
@@ -68,14 +75,6 @@ internal class ShadowRenderer : Control
|
||||
_layout.Children.Add(_maskContent);
|
||||
}
|
||||
|
||||
protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
{
|
||||
base.OnAttachedToVisualTree(e);
|
||||
HorizontalAlignment = HorizontalAlignment.Stretch;
|
||||
VerticalAlignment = VerticalAlignment.Stretch;
|
||||
IsHitTestVisible = false;
|
||||
}
|
||||
|
||||
private Border CreateMaskContent()
|
||||
{
|
||||
var maskContent = new Border
|
||||
|
||||
@@ -197,14 +197,6 @@ public class Icon : Control,
|
||||
this.BindMotionProperties();
|
||||
}
|
||||
|
||||
public override void ApplyTemplate()
|
||||
{
|
||||
base.ApplyTemplate();
|
||||
BuildSourceRenderData();
|
||||
SetupFilledBrush();
|
||||
ConfigureTransitions();
|
||||
}
|
||||
|
||||
private void ConfigureTransitions()
|
||||
{
|
||||
if (IsMotionEnabled)
|
||||
@@ -440,6 +432,9 @@ public class Icon : Control,
|
||||
_animationCancellationTokenSource = new CancellationTokenSource();
|
||||
_animation.RunAsync(this, _animationCancellationTokenSource.Token);
|
||||
}
|
||||
BuildSourceRenderData();
|
||||
SetupFilledBrush();
|
||||
ConfigureTransitions();
|
||||
}
|
||||
|
||||
protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)
|
||||
|
||||
Reference in New Issue
Block a user