views:

181

answers:

2

When creating a custom column design for a Silverlight DataGrid, is there any way to bind or make use of the DataGrid's SelectedItem property?

I wish to display a static element, but have it only visible for the row that is selected.

A simple example of what I'm after:

<data:DataGrid>
        <data:DataGrid.Columns>

            ...

            <data:DataGridTemplateColumn>
                <data:DataGridTemplateColumn.CellTemplate>
                    <DataTemplate>
                        <TextBlock Text="Selected" Visibility="{IsSelected ? Visible : Collapsed}">
                    </DataTemplate>
                </data:DataGridTemplateColumn.CellTemplate>
            </data:DataGridTemplateColumn>

            ...

        </data:DataGrid.Columns>
</data:DataGrid>
  • The column does not need to contain any other elements or bindings.
  • It does not need to control the Visibility property specifically - any means that hides the element on all rows except the selected row will do.

Can this be done with styles? (Note that there is already one style applied to the DataGrid).

A: 

Does RowDetails meet your needs?

Mark Cooper
A: 

Ultimately I made do with a work around - the class used as the ItemSource had a Selected property added which was automatically updated to sync with changes to the list. Then I added a Visiblity property (I could have used a converter as well) to converted the boolean selected to a visibility value, which was used to control the visual appearance of controls in a column of the selected item in the list.

David