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?
If you set the style at hand, it makes sense to define it also at in code (new style, new setter, …) it seems to me you question is rather : “how to get resources from code behind ?”.