12 changed files with 86 additions and 18 deletions
|
After Width: | Height: | Size: 1.1 KiB |
@ -0,0 +1,53 @@ |
|||
using System; |
|||
using System.Collections.Generic; |
|||
using System.Globalization; |
|||
using System.Linq; |
|||
using System.Text; |
|||
using System.Threading.Tasks; |
|||
using Avalonia.Controls; |
|||
using Avalonia.Platform; |
|||
using OmniXaml.TypeConversion; |
|||
|
|||
namespace Avalonia.Markup.Xaml.Converters |
|||
{ |
|||
class IconTypeConverter : ITypeConverter |
|||
{ |
|||
public bool CanConvertFrom(IValueContext context, Type sourceType) |
|||
{ |
|||
return sourceType == typeof(string); |
|||
} |
|||
|
|||
public bool CanConvertTo(IValueContext context, Type destinationType) |
|||
{ |
|||
return false; |
|||
} |
|||
|
|||
public object ConvertFrom(IValueContext context, CultureInfo culture, object value) |
|||
{ |
|||
var uri = new Uri((string)value, UriKind.RelativeOrAbsolute); |
|||
var baseUri = GetBaseUri(context); |
|||
var scheme = uri.IsAbsoluteUri ? uri.Scheme : "file"; |
|||
|
|||
switch (scheme) |
|||
{ |
|||
case "file": |
|||
return new Icon((string)value); |
|||
default: |
|||
var assets = AvaloniaLocator.Current.GetService<IAssetLoader>(); |
|||
return new Icon(assets.Open(uri, baseUri)); |
|||
} |
|||
} |
|||
|
|||
public object ConvertTo(IValueContext context, CultureInfo culture, object value, Type destinationType) |
|||
{ |
|||
throw new NotImplementedException(); |
|||
} |
|||
|
|||
private Uri GetBaseUri(IValueContext context) |
|||
{ |
|||
object result; |
|||
context.ParsingDictionary.TryGetValue("Uri", out result); |
|||
return result as Uri; |
|||
} |
|||
} |
|||
} |
|||
Loading…
Reference in new issue