Files
WinWARP/WinWARP.Ui/Helpers/ServerTemplateSelector.cs
2026-09-09 16:19:45 +03:00

35 lines
1021 B
C#

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
};
}
}