如何在ItemTemplate使用的IValueConverter?
<ListBox x:Name="List1" >
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Converter={StaticResource NumberConverter}}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
public class NumberConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
if (value is int[])
{
int[] intValues = (int[])value;
return String.Join(",", intValues);
}
else return Binding.DoNothing;
}
public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Convert(value, targetType, parameter, culture);
}
}
+1有趣的不知道我有一个格式在那里,但演员似乎并没有工作的联接。 – Prix 2011-04-18 04:51:35
您使用的是.NET 4.0还是使用的是早期版本? – 2011-04-18 04:53:44
对不起我......我被绑在3.5 – Prix 2011-04-18 04:54:32