且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

子字符串绑定字符串

更新时间:2021-08-15 23:26:12

这里你需要的是一个转换器.添加一个转换器参数来指示索引.

What you need here is a converter. Add a converter parameter to indicate the index.

public class DelimiterConverter : IValueConverter
{
    public object Convert(Object value, Type targetType, object parameter, CultureInfo culture)
    {
        string[] values = ((string)value).Split("|");
        int index = int.Parse((string)parameter);
        return values[index];
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        return "";
    }

然后您只需使用 ConverterParameter 属性指定 XAML 中值的索引.

Then you just specify the index of the value in XAML with the ConverterParameter attribute.