public class CustomStyleSelector : StyleSelector
{
public override Style SelectStyle(object item, DependencyObject container)
{
var businessObject = item as BusinessObjects;
Style cellStyle1 = new Style(typeof(GridCell));
cellStyle1.Setters.Add(new Setter(GridCell.BackgroundProperty, newSolidColorBrush(Colors.YellowGreen) { Opacity = 0.2 }));
Style cellStyle2 = new Style(typeof(GridCell));
cellStyle2.Setters.Add(new Setter(GridCell.BackgroundProperty, newSolidColorBrush(Colors.CornflowerBlue) { Opacity = 0.2 }));
if (businessObject != null)
{
if (businessObject.EmployeeGender == "Male")
return cellStyle1;
else
return cellStyle2;
}
return base.SelectStyle(item, container);
}
} |
var businessObject = item as BusinessObjects;
bool isSelected = dataGrid.SelectedItems.Contains(businessObject); |