tags:

views:

31

answers:

2

I have a column with a button for edit the row, but the id key is not a only value, but three value. How can I set the three value in the button so that when onclick the button, I can get three value in the code behind?

The Column

                    <dg:DataGridTemplateColumn Header="Edit">
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Content="Adjust" DataContext="{Binding wId1}" Click="EditButton_Click" />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                </dg:DataGridTemplateColumn>

I wanna pass wId1, wId2, wId3. Besides, it is possible to pass a value on that with string value wId1+wId2+wId3?

Please advice me any reading about this, thanks a lot.

A: 

You can bind to any public property, so one option might be to have a property that simply returns the concatenated strings? Something Along the lines of :

public string ConcatenatedValues
{
    get
    {
     return wId1 + wId2 + wId3;
    }
}

And then bind to that. Would be interesting if there were a more elegant way, but this should get the job done.

PortageMonkey
+1  A: 

Why you don't bind the whole object the DataContext by using {Binding}. In the code behind you can cast the DataContext to your object type and access whatever attribute you want.

You can also have a custom attribute with an array or list of the different Ids and bind it.

If you want for some reason to pass only the Ids to the code behind you can use a ValueConverter that return only a list or an array to the Ids.

{Binding Converter={StaticResource MyConverter}}

Hope it helps.

Zied