How can I programmatically highlight a DataGrid cell in Silverlight?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You’ll need to do the following:
IsSelectedInChart) to your data item class. This property must bepublicand must raise theINotifyPropertyChanged.PropertyChangedevent whenever its value changes.lineseries_SelectionChangedyou should find the data item that corresponds to the selected point and setIsSelectedInCharttotruefor it and tofalsefor others.DataGridRowthat exist in theDataGridhave aBindingset to theirBackgroundproperty withPath=IsSelectedInChartand a custom `IValueConverter’.The converter should look like this:
The last step is the trickiest. It may be implemented by overriding the
DataGridRowStyle. One approach is shown in https://stackoverflow.com/a/4268159/795861, another one in https://stackoverflow.com/a/3542179/795861. Check those out.All these steps are required since you’re likely to have a lot of rows in the
DataGrid. It uses UI virtualization which makes it impossible to simple set theBackgroundproperty on the requiredDataGridRowbecause a single row object is used to present multiple data items. Thus, the only way to make it work with scrolling is binding the background to the data items.UPDATE
To highlight cells in a column that is known at design time, set DataGridColumn.CellStyle property to that column definition instead of setting the row style:
Should work, although I haven’t tried. The xaml does the same as I’ve suggested for highlighting entire rows, but applies it to cells in a specific column.