我有绑定到 Student 类型的集合的 ItemsControl。在 ItemTemplate 内部,我有一个 TextBox,它使用 IValueConverter 进行一些自定义计算和逻辑。我想将实际的 Student 对象传递给值转换器,而不是它的属性。我怎样才能做到这一点?这是我的代码示例。
<ItemsControl ItemsSource="{Binding StudentList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
<TextBlock Text="{Binding ????, Converter={StaticResource MyConverter}}" />
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
在代码中我有这个
public class MyValueConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
// I want 'value' to be of type Student.
return null;
}
}