21
我有ItemsControl绑定到Student类型的集合。 ItemTemplate里面我有一个TextBox,它使用IValueConverter来做一些自定义的计算和逻辑。我想将实际的Student对象传递给值转换器,而不是它的一个属性。我怎样才能做到这一点?这是我的代码示例。WPF将父级绑定对象传递给转换器
<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;
}
}
谢谢你,我会去,现在我难堪。 – 2010-12-02 12:49:17