I have a datagrid, whose itemssource is binded to the model by using MVVM.
The data is returned by a stored procedure, for a particular row say for row with code “A”, I wish to display data only in certain columns, the rest of the columns should display empty string.
How can I create a converter for this?
I have a datagrid, whose itemssource is binded to the model by using MVVM.
Share
There are couple of ways you can do that.
The first and easy approach is to massage the data in the model itself so you have the proper data binding.
The other approach is head on model. Here is how you do it, lets say you have class Product and it has Name and Color in it. If the Color is red then do not want to show the name. So my XAML would look like the following
My code behind is nothing but stright data binding
My converter will have
** The trick in here is the binding, I am binding to the full row and pass the column name as the parameter.This way, even column is generating, value converter is called everytime and you can apply your logic to it.