31 lines
977 B
C#
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();
|
|
} |