美文网首页
WPF text binding with List

WPF text binding with List

作者: 残月星辰梦 | 来源:发表于2019-03-21 15:31 被阅读0次

xaml 调用:

<TextBlock Text="{Binding Path=Logs,Converter={StaticResource ListToStringConverter}}"/>

ValueConverter

[ValueConversion(typeof(List<string>), typeof(string))]
public class ListToStringConverter : IValueConverter
{

    public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        if (targetType != typeof(string))
            throw new InvalidOperationException("The target must be a String");

        return String.Join(", ", ((List<string>)value).ToArray());
    }

    public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

相关文章

网友评论

      本文标题:WPF text binding with List

      本文链接:https://www.haomeiwen.com/subject/mwxcvqtx.html