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
No Data
Reply
  • 975
    posted

    I am having a similar problem as above.

    I have a CellValuePresenter style that is bound to a particular cell and changes the colour according to its value. This is used to highlight the status of each row (red, amber or green).

    This works perfectly.

    The problem comes when I want to print - I apply a different FieldLayout to the grid that doesn't apply the CellValuePresenter style to colour the cells, instead it shows an extra column that indicates the status. This is so that with black and white printing, the status is still clearly shown. When I load up the report and generate a preview, having already applied the new FieldLayout, in the print preview, the new column is displayed and the colours are gone, however in applying a FieldLayout, the size of the columns are reset.

    What I want to be able to do, is allow the user to switch the grid between the standard view (cells coloured to show status), and the print view (no colouring, extra status column), so that they can then resize the print view, and print it as seen. The problem is that applying the new FieldLayout to the grid already in place, the view doesn't update.

    Is there any way to force the grid to update and show the changes of applying the new FieldLayout?

Children
  • 560
    posted in reply to Rob

    I tried your IsFieldActiveTest.zip  Project, and i tested it. It works fine to change the CellValuePresenter at runtime. In the example it changes the whole Field Style, i only need to change the specific Cell. How to do this?

    <DataTrigger Binding="{Binding Path=(Field).(local:Window1.
    IsFieldValueChangedProperty),

     RelativeSource={RelativeSource Self}}" Value="True">
                            <Setter Property="Background"
     Value="Red" />
                        </DataTrigger>


    public static readonly DependencyProperty IsFieldValueChangedProperty =
                DependencyProperty.RegisterAttached("IsFieldValueChangedProperty"typeof(bool), typeof(Window1),
                    new FrameworkPropertyMetadata((bool)false));

            public static bool GetIsFieldValueChanged(DependencyObject d)
            {
                return (bool)d.GetValue(IsFieldValueChangedProperty);
            }

            public static void SetIsFieldValueChanged(DependencyObject d, bool value)
            {
                d.SetValue(IsFieldValueChangedProperty, value);
            }

         void grid_CellUpdated(object sender, Infragistics.Windows.DataPresenter.Events.CellUpdatedEventArgs e)
            {
                e.Cell.Field.SetValue(IsFieldValueChangedProperty, true);
            }