Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
55
Setting CellValuePresenterStyle does not auto-refresh
posted

I'm trying to set a static style to the property "CellValuePresenterStyle" of a field, e.g. with some particular background color. However, the field does not get refreshed to reflect the new style.

----------------------------------

 

 

 

object style = xamDataGrid1.TryFindResource("LightGreenBackgroundStyle");

xamDataGrid1.FieldLayouts[0].Fields[0].Settings.CellValuePresenterStyle = (

Style)style;

------------------------------

In the previous 9.1 version , we had a work-around to this problem. i. e. in code, we collapse a record then make it visiable again.

But it does not work anymore in 9.2 version!

Attaching a simple project to reproduce the situation. In the project, supposingly if you click on any cell of the grid, the background color of the first column should become light green.

With 9.1 version it works with the work-around I mentioned.

With 9.2 version it never works. (Feel free to change the reference lib yourself to try out).

 

Thanks for the help!

ChangeCellBackgroundAtRuntime.zip
Parents
  • 9836
    posted

    Hello,

    In 9.1. and 9.2 versions there is no direct way to set the CellValuePresenter style without refreshing the layout. Yes there are couple of workarounds to do this like showing/hiding the fields in 9.1 or grouping/ungrouping in 9.2 but we do not recommend niether of this approaches. You can achieve the same behaviour with a style for the CellValuePresenter and converter for the background color.

    if (e.Type == typeof(Cell))
                {
                    object style = xamDataGrid1.TryFindResource("LightGreenBackgroundStyle");
                    xamDataGrid1.FieldLayouts[0].Fields[0].Settings.CellValuePresenterStyle = (Style)style;

                    xamDataGrid1.FieldLayouts[0].SortedFields.Add(new FieldSortDescription() { FieldName = "name", IsGroupBy=true });
                    xamDataGrid1.FieldLayouts[0].SortedFields.RemoveAt(0);

                }

    Is there any reasons to change the default CellValuePresenter's style in runtime?

     

Reply Children