我有绑定到学生类型的集合的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;
}
} 发布于 2010-12-02 20:44:41
您可以省略路径。这样你就可以得到绑定到的实际对象。
<TextBlock Text="{Binding Converter={StaticResource MyConverter}}"/>或者,如果您想明确说明这一点:
<TextBlock Text="{Binding Path=., Converter={StaticResource MyConverter}}"/>https://stackoverflow.com/questions/4335068
复制相似问题