wpf绑定整个行对象

<DataGrid  ItemsSource="..." IsReadOnly="True" AutoGenerateColumns="False">
    <DataGrid.Columns>
        <DataGridTextColumn Header="ID" Binding="{Binding ID}"/>
        <DataGridTextColumn Header="Klient" Binding="{Binding Name}">
            <DataGridTextColumn.ElementStyle>
                <Style TargetType="{x:Type TextBlock}">
                    <Setter Property="ToolTipService.ToolTip">
                        <Setter.Value>
                            <TextBlock Text="{Binding Path=., Converter={StaticResource converter}}"/>
                        </Setter.Value>
                    </Setter>
                </Style>
            </DataGridTextColumn.ElementStyle>
        </DataGridTextColumn>
    </DataGrid.Columns>
</DataGrid>
public class DateToBrushConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
    {
        CustomTask t = (CustomTask)value;
        Console.WriteLine(t.ToString()); // HERE
        ...
    }

    public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
    {
        throw new NotImplementedException();
    }
}

精简,转自:https://stackoverflow.com/questions/34354936/wpf-passing-datagridrow-object-to-converter

原文地址:https://www.cnblogs.com/linmilove/p/13968153.html