This commit is contained in:
TheXamlGuy
2024-07-17 21:43:58 +01:00
parent efd00ff81a
commit 93c7a43ab4
75 changed files with 231 additions and 183 deletions
+1 -1
View File
@@ -4,7 +4,7 @@ using Toolkit.UI.Controls.Avalonia;
namespace Toolkit.Avalonia;
public class ContentDialogHandler(IDispatcher dispatcher) :
public class ContentDialogHandler :
INotificationHandler<NavigateEventArgs<ContentDialog>>
{
public async Task Handle(NavigateEventArgs<ContentDialog> args)
+1
View File
@@ -142,6 +142,7 @@ public class FrameHandler :
navigationOptions.TransitionInfoOverride =
new SuppressNavigationTransitionInfo();
break;
case "FromLeft":
case "FromRight":
case "FromTop":
+1
View File
@@ -193,6 +193,7 @@ public class Cache<TKey, TValue>(IComparer<TKey> comparer) :
value = default;
return false;
}
private class KeyValuePairComparer<TK, TV>(IComparer<TK> comparer) :
IComparer<KeyValuePair<TK, TV>>
{
-1
View File
@@ -2,7 +2,6 @@
namespace Toolkit.Foundation;
public class Component :
IComponent
{
+1 -2
View File
@@ -1,5 +1,4 @@
namespace Toolkit.Foundation
namespace Toolkit.Foundation
{
public interface IContentFactory
{
@@ -1,6 +1,7 @@
using Microsoft.Extensions.DependencyInjection;
namespace Toolkit.Foundation;
public static class IServiceCollectionExtensions
{
public static IServiceCollection AddCache<TKey, TValue>(this IServiceCollection services)
-1
View File
@@ -160,5 +160,4 @@ public class Mediator(IHandlerProvider handlerProvider,
return handlers.SelectMany(entry => entry.Value).ToList();
}
}
-1
View File
@@ -2,5 +2,4 @@
public static class MediatorExtensions
{
}
@@ -1,6 +1,5 @@
namespace Toolkit.Foundation;
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true, Inherited = true)]
public class NotificationAttribute(Type type,
object key) : Attribute
+2 -5
View File
@@ -76,7 +76,6 @@ public partial class Observable(IServiceProvider provider,
public virtual void OnInitialize()
{
}
public virtual void Initialize()
@@ -129,10 +128,9 @@ public partial class Observable<TValue> :
protected virtual void OnValueChanged()
{
}
partial void OnValueChanged(TValue? value) => OnValueChanged();
private partial void OnValueChanged(TValue? value) => OnValueChanged();
}
public partial class Observable<TKey, TValue> :
@@ -160,8 +158,7 @@ public partial class Observable<TKey, TValue> :
protected virtual void OnValueChanged()
{
}
partial void OnValueChanged(TValue? value) => OnValueChanged();
private partial void OnValueChanged(TValue? value) => OnValueChanged();
}
+7 -11
View File
@@ -181,6 +181,7 @@ public partial class ObservableCollection<TItem> :
}
}
break;
case NotifyCollectionChangedAction.Remove:
if (args.OldItems is not null)
{
@@ -193,6 +194,7 @@ public partial class ObservableCollection<TItem> :
}
}
break;
case NotifyCollectionChangedAction.Reset:
Clear();
@@ -263,7 +265,6 @@ public partial class ObservableCollection<TItem> :
}
catch (InvalidCastException)
{
}
Add(item!);
@@ -296,7 +297,6 @@ public partial class ObservableCollection<TItem> :
Disposer.Dispose(item);
Disposer.Remove(this, item);
}
}
ClearItems();
@@ -501,7 +501,6 @@ public partial class ObservableCollection<TItem> :
public virtual void OnInitialize()
{
}
public virtual void Initialize()
@@ -722,7 +721,7 @@ public partial class ObservableCollection<TItem> :
CollectionChanged?.Invoke(this, args);
}
partial void OnIsActivatedChanged(bool value)
private partial void OnIsActivatedChanged(bool value)
{
if (value)
{
@@ -734,7 +733,7 @@ public partial class ObservableCollection<TItem> :
}
}
partial void OnSelectedItemChanged(TItem? oldValue, TItem? newValue)
private partial void OnSelectedItemChanged(TItem? oldValue, TItem? newValue)
{
if (oldValue is ISelectable oldSelection)
{
@@ -752,7 +751,6 @@ public partial class ObservableCollection<TItem> :
protected virtual void OnSelectedItemChanged()
{
}
private void UpdateSelection(TItem item)
@@ -786,17 +784,16 @@ public partial class ObservableCollection<TValue, TViewModel>(IServiceProvider p
protected virtual void OnValueChanged()
{
}
partial void OnValueChanged(TValue value) => OnValueChanged();
private partial void OnValueChanged(TValue value) => OnValueChanged();
}
public partial class ObservableCollection<TViewModel, TKey, TValue> :
ObservableCollection<TViewModel>
where TViewModel : notnull, IDisposable
where TKey : notnull
{
{
[ObservableProperty]
private TKey key;
@@ -832,10 +829,9 @@ public partial class ObservableCollection<TViewModel, TKey, TValue> :
protected virtual void OnValueChanged()
{
}
partial void OnValueChanged(TValue value) => OnValueChanged();
private partial void OnValueChanged(TValue value) => OnValueChanged();
}
public class ObservableCollection :
+1
View File
@@ -19,6 +19,7 @@ public static class TupleExtensions
(T3)Convert.ChangeType(parameters[2], typeof(T3)),
(T4)Convert.ChangeType(parameters[3], typeof(T4))
);
public static (T1, T2, T3, T4, T5) CreateValueTuple<T1, T2, T3, T4, T5>(this object[] parameters) => (
(T1)Convert.ChangeType(parameters[0], typeof(T1)),
(T2)Convert.ChangeType(parameters[1], typeof(T2)),
+3 -1
View File
@@ -9,6 +9,7 @@ public class Validation(IValidatorCollection validators) :
private readonly ValidationErrorCollection errors = [];
public event PropertyChangedEventHandler? PropertyChanged;
public IReadOnlyDictionary<string, string> Errors =>
errors.AsReadOnly();
@@ -36,7 +37,6 @@ public class Validation(IValidatorCollection validators) :
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public async Task<bool> Validate<TProperty>(Expression<Func<TProperty>> property,
ValidationRule[] rules)
{
@@ -109,11 +109,13 @@ public class Validation(IValidatorCollection validators) :
OnPropertyChanged(nameof(Errors), null, null);
}
}
private void Clear()
{
errors.Clear();
OnPropertyChanged(nameof(Errors), null, null);
}
private string GetPropertyName<T>(Expression<Func<T>> expression)
{
return expression.Body switch
@@ -1,5 +1,5 @@
using System.Collections.Specialized;
using System.Collections;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
+2 -2
View File
@@ -1,5 +1,5 @@
using System.Diagnostics.CodeAnalysis;
using System.Collections;
using System.Collections;
using System.Diagnostics.CodeAnalysis;
namespace Toolkit.Foundation;
+1 -1
View File
@@ -17,5 +17,5 @@ public partial class ValueViewModel<TValue>(IServiceProvider provider,
{
}
partial void OnValueChanged(TValue? value) => OnChanged(value);
private partial void OnValueChanged(TValue? value) => OnChanged(value);
}
@@ -2,6 +2,7 @@
using Avalonia.Metadata;
namespace Toolkit.UI.Avalonia;
public class ConditionalExpression :
AvaloniaObject,
ICondition
@@ -10,6 +10,8 @@ public class InvokeNavigationViewItemAction :
AvaloniaObject,
IAction
{
private int currentIndex;
public static readonly StyledProperty<int> SelectedIndexProperty =
AvaloniaProperty.Register<InvokeNavigationViewItemAction, int>(nameof(SelectedIndex), 0);
@@ -30,6 +32,11 @@ public class InvokeNavigationViewItemAction :
public object? Execute(object? sender, object? parameter)
{
//if (SelectedIndex == currentIndex)
//{
// return false;
//}
if ((Target ?? sender) is NavigationViewItem navigationViewItem)
{
Dispatcher.UIThread.Post(() =>
@@ -53,6 +60,7 @@ public class InvokeNavigationViewItemAction :
if (collection is { Count: > 0 })
{
navigationView.SetValue(NavigationView.SelectedItemProperty, collection[SelectedIndex]);
currentIndex = SelectedIndex;
}
else
{
@@ -64,5 +72,4 @@ public class InvokeNavigationViewItemAction :
return true;
}
}
@@ -2,7 +2,6 @@
using Avalonia.Controls.Primitives;
using Avalonia.Xaml.Interactivity;
using Toolkit.Foundation;
using Toolkit.UI.Controls.Avalonia;
namespace Toolkit.UI.Avalonia;
@@ -5,6 +5,7 @@ using Avalonia.Media;
using Path = Avalonia.Controls.Shapes.Path;
namespace Toolkit.UI.Controls.Avalonia;
public class ContentBadge :
ContentControl
{
@@ -95,14 +96,17 @@ public class ContentBadge :
offsetX = 0;
offsetY = 0;
break;
case ContentBadgePlacement.TopRight:
offsetX = backgroundWidth - scaledWidth;
offsetY = 0;
break;
case ContentBadgePlacement.BottomLeft:
offsetX = 0;
offsetY = backgroundHeight - scaledHeight;
break;
case ContentBadgePlacement.BottomRight:
offsetX = backgroundWidth - scaledWidth;
offsetY = backgroundHeight - scaledHeight;
@@ -155,4 +159,3 @@ public class ContentBadge :
UpdateBadge();
}
}
@@ -7,4 +7,3 @@ public enum ContentBadgePlacement
BottomLeft,
BottomRight
}
@@ -75,15 +75,14 @@
BadgePath="{TemplateBinding BadgePath}"
BadgePlacement="{TemplateBinding BadgePlacement}"
BadgeSize="{TemplateBinding BadgeSize}"
Foreground="Red"
Foreground="{TemplateBinding BadgeBrush}"
IsBadgeVisible="{TemplateBinding IsBadgeVisible}">
<Grid>
<ContentPresenter
Name="PART_ContentPresenter"
HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding Content}"
/>
Content="{TemplateBinding Content}" />
<Border
Name="SelectionIndicator"
BorderBrush="{DynamicResource AccentFillColorDefaultBrush}"
@@ -29,7 +29,6 @@ public class Overflow :
private static readonly StyledProperty<OverflowTemplateSettings> TemplateSettingsProperty =
AvaloniaProperty.Register<Overflow, OverflowTemplateSettings>(nameof(TemplateSettings));
private readonly ObservableCollection<object> primaryCollection = [];
private readonly ObservableCollection<object> secondaryCollection = [];
@@ -60,6 +59,7 @@ public class Overflow :
get => GetValue(ItemsSourceProperty);
set => SetValue(ItemsSourceProperty, value);
}
[InheritDataTypeFromItems(nameof(ItemsSource))]
public IDataTemplate? ItemTemplate
{
@@ -146,6 +146,7 @@ public class Overflow :
object? selection = args.GetNewValue<object>();
SetValue(SelectedItemProperty, selection);
}
private void OnSourceCollectionChanged(object? sender,
NotifyCollectionChangedEventArgs args)
{
@@ -307,4 +308,3 @@ public class Overflow :
}
}
}
@@ -1,16 +1,14 @@
using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;
namespace Toolkit.UI.Controls.Avalonia;
public class OverflowItem :
ListBoxItem
{
public static readonly StyledProperty<double> BadgeSizeProperty =
AvaloniaProperty.Register<OverflowItem, double>(nameof(BadgeSize), 14);
public static readonly StyledProperty<bool> IsBadgeVisibleProperty =
AvaloniaProperty.Register<OverflowItem, bool>(nameof(IsBadgeVisible), true);
public static readonly StyledProperty<IBrush> BadgeBrushProperty =
AvaloniaProperty.Register<OverflowItem, IBrush>(nameof(BadgeBrush));
public static readonly StyledProperty<string> BadgePathProperty =
AvaloniaProperty.Register<OverflowItem, string>(nameof(BadgePath));
@@ -18,6 +16,18 @@ public class OverflowItem :
public static readonly StyledProperty<ContentBadgePlacement> BadgePlacementProperty =
AvaloniaProperty.Register<OverflowItem, ContentBadgePlacement>(nameof(BadgePlacement), ContentBadgePlacement.BottomRight);
public static readonly StyledProperty<double> BadgeSizeProperty =
AvaloniaProperty.Register<OverflowItem, double>(nameof(BadgeSize), 14);
public static readonly StyledProperty<bool> IsBadgeVisibleProperty =
AvaloniaProperty.Register<OverflowItem, bool>(nameof(IsBadgeVisible), true);
public IBrush BadgeBrush
{
get => GetValue(BadgeBrushProperty);
set => SetValue(BadgeBrushProperty, value);
}
public string BadgePath
{
get => GetValue(BadgePathProperty);
@@ -42,4 +52,3 @@ public class OverflowItem :
set => SetValue(IsBadgeVisibleProperty, value);
}
}
@@ -46,4 +46,3 @@ public class OverflowTemplateSettings :
set => SetValue(SecondarySelectionProperty, value);
}
}
@@ -40,4 +40,3 @@ public class TemplateListBox :
return true;
}
}
@@ -7,7 +7,6 @@ using Avalonia.Media.Imaging;
namespace Toolkit.UI.Controls.Avalonia;
public class PersonPicture : TemplatedControl
{
public static readonly StyledProperty<string> BadgeGlyphProperty =
@@ -8,15 +8,56 @@ public class PersonPictureColourGenerator
{
private readonly string[] colours =
[
"#FFB900", "#FF8C00", "#F7630C", "#CA5010", "#DA3B01", "#EF6950", "#D13438", "#FF4343",
"#E74856", "#E81123", "#EA005E", "#C30052", "#E3008C", "#BF0077", "#C239B3", "#9A0089",
"#0078D7", "#0063B1", "#8E8CD8", "#6B69D6", "#8764B8", "#744DA9", "#B146C2", "#881798",
"#0099BC", "#2D7D9A", "#00B7C3", "#038387", "#00B294", "#018574", "#00CC6A", "#10893E",
"#7A7574", "#5D5A58", "#68768A", "#515C6B", "#567C73", "#486860", "#498205", "#107C10",
"#767676", "#4C4A48", "#69797E", "#4A5459", "#647C64", "#525E54", "#847545", "#7E735F"
"#FFB900",
"#FF8C00",
"#F7630C",
"#CA5010",
"#DA3B01",
"#EF6950",
"#D13438",
"#FF4343",
"#E74856",
"#E81123",
"#EA005E",
"#C30052",
"#E3008C",
"#BF0077",
"#C239B3",
"#9A0089",
"#0078D7",
"#0063B1",
"#8E8CD8",
"#6B69D6",
"#8764B8",
"#744DA9",
"#B146C2",
"#881798",
"#0099BC",
"#2D7D9A",
"#00B7C3",
"#038387",
"#00B294",
"#018574",
"#00CC6A",
"#10893E",
"#7A7574",
"#5D5A58",
"#68768A",
"#515C6B",
"#567C73",
"#486860",
"#498205",
"#107C10",
"#767676",
"#4C4A48",
"#69797E",
"#4A5459",
"#647C64",
"#525E54",
"#847545",
"#7E735F"
];
public Color GenerateColour(string input)
{
byte[] hashBytes = GetHash(input);
@@ -33,7 +33,6 @@ public class SettingsExpander :
set => SetValue(IsToggleableProperty, value);
}
protected override Type StyleKeyOverride =>
typeof(SettingsExpander);
}