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

31 lines
977 B
C#

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Markup;
namespace WinWARP.Ui.Converters;
[MarkupExtensionReturnType(ReturnType = typeof(IValueConverter))]
public class CountryCodeToUriConverter : MarkupExtension, IValueConverter
{
protected override object ProvideValue() => this;
public object Convert(object value, Type targetType, object parameter, string language)
{
if (value is string countryCode)
{
if (!string.IsNullOrWhiteSpace(countryCode))
{
return new Uri($"ms-appx:///Assets/Flags/{countryCode.ToLower()}.svg");
}
else
{
return new Uri("ms-appx:///Assets/Flags/xx.svg");
}
}
else return null;
}
public object ConvertBack(object value, Type targetType, object parameter, string language) => throw new NotImplementedException();
}