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

posted @ 2020-11-13 10:41  随便取个名字算了  阅读(221)  评论(0编辑  收藏  举报