mirror of
https://github.com/AtomUI/AtomUI.git
synced 2026-10-29 15:19:12 +08:00
Refactor(Bindings): Refactor Avatar bindings
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
namespace AtomUIGallery;
|
||||
|
||||
public static class Constants
|
||||
{
|
||||
public const string LanguageCatalog = "AtomUIGallery";
|
||||
}
|
||||
@@ -4,7 +4,7 @@ using AtomUIGallery.Workspace.Views;
|
||||
|
||||
namespace AtomUIGallery.Workspace.Localization.CaseNavigationLang;
|
||||
|
||||
[LanguageProvider(LanguageCode.en_US, CaseNavigation.LanguageId, Constants.LanguageCatalog)]
|
||||
[LanguageProvider(LanguageCode.en_US, CaseNavigation.LanguageId)]
|
||||
internal class en_US : LanguageProvider
|
||||
{
|
||||
public const string General = "General";
|
||||
|
||||
@@ -4,7 +4,7 @@ using AtomUIGallery.Workspace.Views;
|
||||
|
||||
namespace AtomUIGallery.Workspace.Localization.CaseNavigationLang;
|
||||
|
||||
[LanguageProvider(LanguageCode.zh_CN, CaseNavigation.LanguageId, Constants.LanguageCatalog)]
|
||||
[LanguageProvider(LanguageCode.zh_CN, CaseNavigation.LanguageId)]
|
||||
internal class zh_CN : LanguageProvider
|
||||
{
|
||||
public const string General = "通用";
|
||||
|
||||
@@ -4,7 +4,7 @@ using AtomUIGallery.Workspace.Views;
|
||||
|
||||
namespace AtomUIGallery.Workspace.Localization.WorkspaceWindowLang;
|
||||
|
||||
[LanguageProvider(LanguageCode.en_US, WorkspaceWindow.LanguageId, Constants.LanguageCatalog)]
|
||||
[LanguageProvider(LanguageCode.en_US, WorkspaceWindow.LanguageId)]
|
||||
internal class en_US : LanguageProvider
|
||||
{
|
||||
public const string MenuItemSettings = "Settings";
|
||||
|
||||
@@ -4,7 +4,7 @@ using AtomUIGallery.Workspace.Views;
|
||||
|
||||
namespace AtomUIGallery.Workspace.Localization.WorkspaceWindowLang;
|
||||
|
||||
[LanguageProvider(LanguageCode.zh_CN, WorkspaceWindow.LanguageId, Constants.LanguageCatalog)]
|
||||
[LanguageProvider(LanguageCode.zh_CN, WorkspaceWindow.LanguageId)]
|
||||
internal class zh_CN : LanguageProvider
|
||||
{
|
||||
public const string MenuItemSettings = "设置";
|
||||
|
||||
@@ -6,6 +6,5 @@ public interface ILanguageProvider
|
||||
{
|
||||
public LanguageCode LangCode { get; }
|
||||
public string LangId { get; }
|
||||
public string ResourceCatalog { get; }
|
||||
public void BuildResourceDictionary(IResourceDictionary dictionary);
|
||||
}
|
||||
@@ -11,8 +11,6 @@ public abstract class LanguageProvider : ILanguageProvider
|
||||
|
||||
public string LangId { get; }
|
||||
|
||||
public string ResourceCatalog { get; }
|
||||
|
||||
public LanguageProvider()
|
||||
{
|
||||
var type = GetType();
|
||||
@@ -24,7 +22,6 @@ public abstract class LanguageProvider : ILanguageProvider
|
||||
|
||||
LangCode = languageProviderAttribute.LanguageCode;
|
||||
LangId = languageProviderAttribute.LanguageId;
|
||||
ResourceCatalog = languageProviderAttribute.ResourceCatalog;
|
||||
}
|
||||
|
||||
public void BuildResourceDictionary(IResourceDictionary dictionary)
|
||||
|
||||
@@ -4,17 +4,13 @@
|
||||
public class LanguageProviderAttribute : Attribute
|
||||
{
|
||||
public const string DefaultLanguageId = "Default";
|
||||
public const string DefaultResourceCatalog = $"{ResourceCatalogConstants.Root}.{ResourceCatalogConstants.Language}";
|
||||
public LanguageCode LanguageCode { get; }
|
||||
public string LanguageId { get; }
|
||||
public string ResourceCatalog { get; }
|
||||
|
||||
public LanguageProviderAttribute(LanguageCode languageCode,
|
||||
string languageId = DefaultLanguageId,
|
||||
string resourceCatalog = DefaultResourceCatalog)
|
||||
string languageId = DefaultLanguageId)
|
||||
{
|
||||
LanguageCode = languageCode;
|
||||
LanguageId = languageId;
|
||||
ResourceCatalog = resourceCatalog;
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,7 @@ namespace AtomUI.Desktop.Controls;
|
||||
|
||||
public abstract class DataGridAbstractTextColumn : DataGridBoundColumn
|
||||
{
|
||||
#region 公共属性定义
|
||||
#region 公共属性定义
|
||||
|
||||
/// <summary>
|
||||
/// Identifies the FontFamily dependency property.
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Reactive.Disposables;
|
||||
using AtomUI.Controls;
|
||||
using AtomUI.Controls.Commons;
|
||||
using AtomUI.Data;
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Utils;
|
||||
using Avalonia;
|
||||
@@ -121,9 +118,6 @@ public class AvatarGroup : TemplatedControl, IMotionAwareControl
|
||||
private Avatar? _foldCountAvatar;
|
||||
private FlyoutHost? _foldCountFlyout;
|
||||
private StackPanel? _foldCountStackPanel;
|
||||
private readonly Dictionary<Control, CompositeDisposable> _itemBindingDisposables = new();
|
||||
private CompositeDisposable? _foldAvatarBindingDisposables;
|
||||
private CompositeDisposable? _flyoutBindingDisposables;
|
||||
|
||||
static AvatarGroup()
|
||||
{
|
||||
@@ -184,14 +178,6 @@ public class AvatarGroup : TemplatedControl, IMotionAwareControl
|
||||
var items = e.OldItems!.OfType<Control>().ToList();
|
||||
LogicalChildren.RemoveAll(items);
|
||||
VisualChildren.RemoveAll(items);
|
||||
foreach (var child in items)
|
||||
{
|
||||
if (_itemBindingDisposables.TryGetValue(child, out var disposable))
|
||||
{
|
||||
disposable.Dispose();
|
||||
}
|
||||
_itemBindingDisposables.Remove(child);
|
||||
}
|
||||
break;
|
||||
|
||||
case NotifyCollectionChangedAction.Replace:
|
||||
@@ -237,13 +223,11 @@ public class AvatarGroup : TemplatedControl, IMotionAwareControl
|
||||
|
||||
private void ConfigureAvatar(Avatar avatar)
|
||||
{
|
||||
var disposable = new CompositeDisposable();
|
||||
disposable.Add(BindUtils.RelayBind(this, BorderThicknessProperty, avatar, BorderThicknessProperty));
|
||||
disposable.Add(BindUtils.RelayBind(this, IsMotionEnabledProperty, avatar, IsMotionEnabledProperty));
|
||||
disposable.Add(BindUtils.RelayBind(this, ShapeProperty, avatar, ShapeProperty));
|
||||
disposable.Add(BindUtils.RelayBind(this, SizeProperty, avatar, SizeProperty));
|
||||
disposable.Add(BindUtils.RelayBind(this, SizeTypeProperty, avatar, SizeTypeProperty));
|
||||
_itemBindingDisposables.Add(avatar, disposable);
|
||||
avatar[!BorderThicknessProperty] = this[!BorderThicknessProperty];
|
||||
avatar[!IsMotionEnabledProperty] = this[!IsMotionEnabledProperty];
|
||||
avatar[!ShapeProperty] = this[!ShapeProperty];
|
||||
avatar[!SizeProperty] = this[!SizeProperty];
|
||||
avatar[!SizeTypeProperty] = this[!SizeTypeProperty];
|
||||
}
|
||||
|
||||
private Avatar GetFoldCountAvatar()
|
||||
@@ -251,14 +235,13 @@ public class AvatarGroup : TemplatedControl, IMotionAwareControl
|
||||
if (_foldCountAvatar == null)
|
||||
{
|
||||
_foldCountAvatar = new Avatar();
|
||||
_foldAvatarBindingDisposables?.Dispose();
|
||||
_foldAvatarBindingDisposables = new CompositeDisposable();
|
||||
_foldAvatarBindingDisposables.Add(BindUtils.RelayBind(this, BorderThicknessProperty, _foldCountAvatar, BorderThicknessProperty));
|
||||
_foldAvatarBindingDisposables.Add(BindUtils.RelayBind(this, ShapeProperty, _foldCountAvatar, ShapeProperty));
|
||||
_foldAvatarBindingDisposables.Add(BindUtils.RelayBind(this, SizeProperty, _foldCountAvatar, SizeProperty));
|
||||
_foldAvatarBindingDisposables.Add(BindUtils.RelayBind(this, SizeTypeProperty, _foldCountAvatar, SizeTypeProperty));
|
||||
_foldAvatarBindingDisposables.Add(BindUtils.RelayBind(this, FoldInfoAvatarForegroundProperty, _foldCountAvatar, Avatar.ForegroundProperty));
|
||||
_foldAvatarBindingDisposables.Add(BindUtils.RelayBind(this, FoldInfoAvatarBackgroundProperty, _foldCountAvatar, Avatar.BackgroundProperty));
|
||||
|
||||
_foldCountAvatar[!BorderThicknessProperty] = this[!BorderThicknessProperty];
|
||||
_foldCountAvatar[!ShapeProperty] = this[!ShapeProperty];
|
||||
_foldCountAvatar[!SizeProperty] = this[!SizeProperty];
|
||||
_foldCountAvatar[!SizeTypeProperty] = this[!SizeTypeProperty];
|
||||
_foldCountAvatar[!ForegroundProperty] = this[!FoldInfoAvatarForegroundProperty];
|
||||
_foldCountAvatar[!BackgroundProperty] = this[!FoldInfoAvatarBackgroundProperty];
|
||||
}
|
||||
|
||||
return _foldCountAvatar;
|
||||
@@ -270,15 +253,15 @@ public class AvatarGroup : TemplatedControl, IMotionAwareControl
|
||||
var foldCountAvatar = GetFoldCountAvatar();
|
||||
if (_foldCountFlyout == null)
|
||||
{
|
||||
_flyoutBindingDisposables?.Dispose();
|
||||
_flyoutBindingDisposables = new CompositeDisposable();
|
||||
_foldCountFlyout = new FlyoutHost();
|
||||
_foldCountFlyout.ZIndex = Int32.MaxValue;
|
||||
_foldCountFlyout.Content = foldCountAvatar;
|
||||
_foldCountStackPanel = new StackPanel();
|
||||
_foldCountStackPanel.Orientation = Orientation.Horizontal;
|
||||
_flyoutBindingDisposables.Add(BindUtils.RelayBind(this, GroupSpaceProperty, _foldCountStackPanel, StackPanel.SpacingProperty));
|
||||
_flyoutBindingDisposables.Add(BindUtils.RelayBind(this, FoldAvatarFlyoutTriggerTypeProperty, _foldCountFlyout, FlyoutHost.TriggerProperty));
|
||||
|
||||
_foldCountStackPanel[!StackPanel.SpacingProperty] = this[!GroupSpaceProperty];
|
||||
_foldCountFlyout[!FlyoutHost.TriggerProperty] = this[!FoldAvatarFlyoutTriggerTypeProperty];
|
||||
|
||||
_foldCountFlyout.Flyout = new Flyout
|
||||
{
|
||||
Content = _foldCountStackPanel
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Reactive.Disposables;
|
||||
using AtomUI.Controls;
|
||||
using AtomUI.Data;
|
||||
using AtomUI.Desktop.Controls.Themes;
|
||||
using AtomUI.Theme;
|
||||
using AtomUI.Theme.Styling;
|
||||
@@ -212,7 +210,6 @@ public class Card : HeaderedContentControl,
|
||||
#endregion
|
||||
|
||||
private CardActionPanel? _cardActionPanel;
|
||||
private CompositeDisposable? _contentBindingDisposables;
|
||||
|
||||
static Card()
|
||||
{
|
||||
@@ -262,7 +259,6 @@ public class Card : HeaderedContentControl,
|
||||
|
||||
private void ConfigureContentType()
|
||||
{
|
||||
_contentBindingDisposables?.Dispose();
|
||||
// 暂时只能探测 Content 直接指定的情况
|
||||
if (Content is CardMetaContent)
|
||||
{
|
||||
@@ -271,16 +267,14 @@ public class Card : HeaderedContentControl,
|
||||
else if (Content is CardTabsContent cardTabsContent)
|
||||
{
|
||||
SetCurrentValue(ContentTypeProperty, CardContentType.Tabs);
|
||||
_contentBindingDisposables = new CompositeDisposable();
|
||||
_contentBindingDisposables.Add(BindUtils.RelayBind(this, IsMotionEnabledProperty, cardTabsContent, CardTabsContent.IsMotionEnabledProperty));
|
||||
_contentBindingDisposables.Add(BindUtils.RelayBind(this, SizeTypeProperty, cardTabsContent, CardTabsContent.SizeTypeProperty));
|
||||
cardTabsContent[!IsMotionEnabledProperty] = this[!IsMotionEnabledProperty];
|
||||
cardTabsContent[!SizeTypeProperty] = this[!SizeTypeProperty];
|
||||
}
|
||||
else if (Content is CardGridContent cardGridContent)
|
||||
{
|
||||
SetCurrentValue(ContentTypeProperty, CardContentType.Grid);
|
||||
_contentBindingDisposables = new CompositeDisposable();
|
||||
_contentBindingDisposables.Add(BindUtils.RelayBind(this, IsMotionEnabledProperty, cardGridContent, CardGridContent.IsMotionEnabledProperty));
|
||||
_contentBindingDisposables.Add(BindUtils.RelayBind(this, SizeTypeProperty, cardGridContent, CardGridContent.SizeTypeProperty));
|
||||
cardGridContent[!IsMotionEnabledProperty] = this[!IsMotionEnabledProperty];
|
||||
cardGridContent[!SizeTypeProperty] = this[!SizeTypeProperty];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Reactive.Disposables;
|
||||
using AtomUI.Controls;
|
||||
using AtomUI.Data;
|
||||
using AtomUI.Desktop.Controls.Themes;
|
||||
using Avalonia;
|
||||
using Avalonia.Controls;
|
||||
@@ -43,8 +41,6 @@ public class CardGridContent : ItemsControl
|
||||
internal static readonly StyledProperty<bool> IsMotionEnabledProperty =
|
||||
MotionAwareControlProperty.IsMotionEnabledProperty.AddOwner<CardGridContent>();
|
||||
|
||||
private readonly Dictionary<CardGridItem, CompositeDisposable> _itemsBindingDisposables = new();
|
||||
|
||||
public SizeType SizeType
|
||||
{
|
||||
get => GetValue(SizeTypeProperty);
|
||||
@@ -61,32 +57,6 @@ public class CardGridContent : ItemsControl
|
||||
|
||||
private ItemsPresenter? _itemsPresenter;
|
||||
|
||||
public CardGridContent()
|
||||
{
|
||||
Items.CollectionChanged += HandleCollectionChanged;
|
||||
}
|
||||
|
||||
private void HandleCollectionChanged(object? sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (e.OldItems != null)
|
||||
{
|
||||
if (e.Action == NotifyCollectionChangedAction.Remove && e.OldItems.Count > 0)
|
||||
{
|
||||
foreach (var item in e.OldItems)
|
||||
{
|
||||
if (item is CardGridItem gridItem)
|
||||
{
|
||||
if (_itemsBindingDisposables.TryGetValue(gridItem, out var disposable))
|
||||
{
|
||||
disposable.Dispose();
|
||||
_itemsBindingDisposables.Remove(gridItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override Control CreateContainerForItemOverride(object? item, int index, object? recycleKey)
|
||||
{
|
||||
return new CardGridItem();
|
||||
@@ -113,19 +83,12 @@ public class CardGridContent : ItemsControl
|
||||
|
||||
if (ItemTemplate != null)
|
||||
{
|
||||
disposables.Add(BindUtils.RelayBind(this, ItemTemplateProperty, gridItem, CardGridItem.ContentTemplateProperty));
|
||||
gridItem[!CardGridItem.ContentTemplateProperty] = this[!ItemTemplateProperty];
|
||||
}
|
||||
disposables.Add(BindUtils.RelayBind(this, SizeTypeProperty, gridItem, CardGridItem.SizeTypeProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, IsEnabledProperty, gridItem, CardGridItem.IsEnabledProperty));
|
||||
disposables.Add(BindUtils.RelayBind(this, IsMotionEnabledProperty, gridItem, CardGridItem.IsMotionEnabledProperty));
|
||||
gridItem[!SizeTypeProperty] = this[!SizeTypeProperty];
|
||||
gridItem[!IsEnabledProperty] = this[!IsEnabledProperty];
|
||||
gridItem[!IsMotionEnabledProperty] = this[!IsMotionEnabledProperty];
|
||||
PrepareCardGridItem(gridItem, item, index, disposables);
|
||||
|
||||
if (_itemsBindingDisposables.TryGetValue(gridItem, out var oldDisposables))
|
||||
{
|
||||
oldDisposables.Dispose();
|
||||
_itemsBindingDisposables.Remove(gridItem);
|
||||
}
|
||||
_itemsBindingDisposables.Add(gridItem, disposables);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -7,7 +7,6 @@ internal class LanguageInfo
|
||||
/// </summary>
|
||||
public string? TargetNamespace { get; internal set; }
|
||||
public string Namespace { get; internal set; } = string.Empty;
|
||||
public string ResourceCatalog { get; internal set; } = string.Empty;
|
||||
public string LanguageId { get; internal set; } = string.Empty;
|
||||
public string LanguageCode { get; internal set; } = string.Empty;
|
||||
public string ClassName { get; internal set; } = string.Empty;
|
||||
|
||||
@@ -90,12 +90,6 @@ internal class LanguageProviderWalker : CSharpSyntaxWalker
|
||||
{
|
||||
LanguageInfo.LanguageId = languageId;
|
||||
}
|
||||
|
||||
if (attribute.ConstructorArguments.Any() &&
|
||||
attribute.ConstructorArguments[2].Value is string resourceCatalog)
|
||||
{
|
||||
LanguageInfo.ResourceCatalog = resourceCatalog;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user