Idk, dev work goin on
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.Text;
|
||||
using Jeffijoe.MessageFormat;
|
||||
|
||||
namespace WinWARP.Ui.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// Provides methods to determine the plural category of a number based on the specified locale and whether it is an ordinal or cardinal number.
|
||||
/// </summary>
|
||||
public static class PluralCategory
|
||||
{
|
||||
private static readonly MessageFormatter Formatter = new();
|
||||
|
||||
private static readonly string CardinalPattern =
|
||||
"{n, plural, zero{zero} one{one} two{two} few{few} many{many} other{other}}";
|
||||
|
||||
private static readonly string OrdinalPattern =
|
||||
"{n, selectordinal, zero{zero} one{one} two{two} few{few} many{many} other{other}}";
|
||||
|
||||
public static string GetCategory(double number, CultureInfo locale, bool isOrdinal = false)
|
||||
{
|
||||
var pattern = isOrdinal ? OrdinalPattern : CardinalPattern;
|
||||
var args = new Dictionary<string, object?> { { "n", number } };
|
||||
|
||||
// Formatter resolves the logic and returns the matched keyword block literal
|
||||
return Formatter.FormatMessage(pattern, args, locale);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.UI.Xaml;
|
||||
using Microsoft.UI.Xaml.Controls;
|
||||
using WinWARP.Core.ViewModels.Wrappers;
|
||||
|
||||
namespace WinWARP.Ui.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A DataTemplateSelector that selects the appropriate DataTemplate based on the type of server item (StandaloneServerViewModel or SubscriptionServerViewModel).
|
||||
/// </summary>
|
||||
public class ServerTemplateSelector : DataTemplateSelector
|
||||
{
|
||||
public DataTemplate StandaloneTemplate
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
public DataTemplate SubscriptionTemplate
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
|
||||
protected override DataTemplate SelectTemplateCore(object item)
|
||||
{
|
||||
// Evaluate the type of the item currently being rendered in the list row
|
||||
return item switch
|
||||
{
|
||||
StandaloneServerViewModel => StandaloneTemplate,
|
||||
SubscriptionServerViewModel => SubscriptionTemplate,
|
||||
_ => base.SelectTemplateCore(item) // Fallback if type doesn't match
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,9 @@ using Microsoft.UI.Xaml.Markup;
|
||||
|
||||
namespace WinWARP.Ui.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A markup extension that allows you to specify a <see cref="Type"/> in XAML.
|
||||
/// </summary>
|
||||
[MarkupExtensionReturnType(ReturnType = typeof(Type))]
|
||||
public sealed class TypeExtension : MarkupExtension
|
||||
{
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Microsoft.UI.Xaml;
|
||||
|
||||
namespace WinWARP.Ui.Helpers;
|
||||
|
||||
/// <summary>
|
||||
/// A helper class to track the XamlRoot of a frame's content via DI.
|
||||
/// </summary>
|
||||
public class XamlRootTracker
|
||||
{
|
||||
public XamlRoot? XamlRoot
|
||||
{
|
||||
get; set;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user