34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
|
using System;
|
||
|
using System.Globalization;
|
||
|
using Avalonia.Data;
|
||
|
using Avalonia.Data.Converters;
|
||
|
using Ocarina2.Models;
|
||
|
|
||
|
namespace Ocarina2.Converter;
|
||
|
|
||
|
public class SongMetadataConverter:IValueConverter
|
||
|
{
|
||
|
public object? Convert(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||
|
{
|
||
|
if(!int.TryParse(parameter as string,out var p)) return new BindingNotification(new InvalidCastException(), BindingErrorType.Error); // get int param
|
||
|
// for null return placeholders
|
||
|
if (value == null && p == 1) return "Nothing";
|
||
|
if (value == null && p == 2) return "Start playing something...";
|
||
|
|
||
|
if (value is MusicFile m)
|
||
|
{
|
||
|
if (p == 1)
|
||
|
{
|
||
|
return m.Metadata.Tag.Title;
|
||
|
}
|
||
|
|
||
|
return m.Metadata.Tag.FirstPerformer == ""?"Unknown":m.Metadata.Tag.FirstPerformer;
|
||
|
}
|
||
|
return new BindingNotification(new InvalidCastException(), BindingErrorType.Error);
|
||
|
}
|
||
|
|
||
|
public object? ConvertBack(object? value, Type targetType, object? parameter, CultureInfo culture)
|
||
|
{
|
||
|
throw new NotImplementedException();
|
||
|
}
|
||
|
}
|