Question: I am trying to set the cell style in code but have been unable to do so:

xaml: 

```
CellStyle="{StaticResource DefaultCell}"

```

Which works perfect.

In the code behind I have tired a few variations of: 

```
datagrid.CellStyle = Resources["DefaultCell"] as Style;
datagrid.CellStyle = (Style)FindResource("DefaultCell");

```

but have been unable to get this to work, any ideas?

Answer: 
Have you tried method `FindResource("DefaultCell")` ?
Do you set style type?

```
<Style TargetType="local:DataGridCell">
...
</Style>

```