public class SelectorClass : StyleSelector
{
protected override Style SelectStyleCore(object item, DependencyObject container)
{
var data = item as BusinessObjects;
if (data != null)
{
if(data.EmployeeAge<45)
return App.Current.Resources["test"] as Style;
}
return base.SelectStyleCore(item, container);
}
} |
this.datagrid.CurrentCellActivated += datagrid_CurrentCellActivated;
void datagrid_CurrentCellActivated(object sender, CurrentCellActivatedEventArgs args)
{
GridCell cell;
Style cellStyle;
if (datagrid.SelectionController.CurrentCellManager.CurrentCell != null)
{
cell = (this.datagrid.SelectionController.CurrentCellManager.CurrentCell.ColumnElement as GridCell);
cellStyle = cell.Style;
if(cellStyle!=null)
{
//Write your code
}
}
} |
public class SelectorClass : StyleSelector
{
public override Style SelectStyle(object item, DependencyObject container)
{
var gridCell = container as GridCell;
if (gridCell == null)
return base.SelectStyle(item, container);
var dataColumnBase = gridCell.ColumnBase;
if(dataColumnBase.IsCurrentCell)
{
if (gridCell.Style == null)
return App.Current.Resources["test"] as Style;
if(gridCell.Style != null)
{
var setter = (gridCell.Style.Setters.FirstOrDefault(o => (o as Setter).Value.Equals("test")) as Setter);
var styleName = setter != null ? setter.Value : string.Empty;
if(string.IsNullOrEmpty(styleName.ToString()))
return App.Current.Resources["test"] as Style;
}
}
}
} |
<Application.Resources>
<ResourceDictionary>
<Style x:Key="test" TargetType="Grid:GridCell">
<Setter Property="Name" Value="test"/>
<Setter Property="Background" Value="PowderBlue" />
<Setter Property="FontWeight" Value="SemiBold" />
</Style>
</ResourceDictionary>
</Application.Resources> |
public class GridCellRedEvo : StyleSelector
{
protected override Style SelectStyleCore(object item, DependencyObject container)
{
var gridCell = container as GridCell;
if (gridCell == null)
return base.SelectStyle(item, container);
var dataColumnBase = gridCell.ColumnBase;
// if (dataColumnBase.IsCurrentCell)
{
if (gridCell.Style == null)
return App.Current.Resources["Redtest"] as Style;
if (gridCell.Style != null)
{
var setter = (gridCell.Style.Setters.FirstOrDefault(o => (o as Setter).Value.Equals("testName")) as Setter);
var styleName = setter != null ? setter.Value : string.Empty;
if (string.IsNullOrEmpty(styleName.ToString()))
return App.Current.Resources["Redtest"] as Style;
}
}
return base.SelectStyleCore(item, container);
}
} |