John Threepwood
John Threepwood

Reputation: 16143

How to bind the object itself to a DataGrid?

Within a DataGrid one can bind a property to a column. For example:

Binding="{Binding MyProperty, Converter={StaticResource MyConverter}}"

Is it possible to bind the object itself to the column (not the property only)?

The reason behind this question is, that the converter MyConverter needs more information of the whole object to display the property correctly. When using a binding like Binding MyProperty the converty only gets the property information.

Upvotes: 0

Views: 207

Answers (2)

d.moncada
d.moncada

Reputation: 17402

You can do this two ways:

Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource MyConverter}}"

or

Binding="{Binding Path=., Converter={StaticResource MyConverter}}"

Upvotes: 1

Flat Eric
Flat Eric

Reputation: 8111

Just leave away the path information:

Binding="{Binding Converter={StaticResource MyConverter}}"

or alternatively use an IMultiValueConverter and bind the different properties you need.

Upvotes: 2

Related Questions