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.
----------------------------------
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!
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); }
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?
The CellValuePresenter are virtualized when they are scrolled out of view, so this could be the reasons for this. If you are saving some information in the Tag of the CVP, it is lost. The cell's tag however should be working. Do you have any binding exceptions in the output window? If not, can you provide a small sample with this behavior?
Thanks for the reply.
I tried to bind the cell background color with the tag of the DataRecord and it works.
PS: But when i tried to bind to the tag of the Cell, it encountered the same problem (no refreshing until hide/show the column).
And is there any reason why setting the CellValuePresenter directly does not work? Is it a bug? Since this property is not read-only, it makes full sense that the user will expect the style to be effective immediately after the set action.
Thanks.
Hello,
There is another approach that you can use in this scenario. You do not need to apply a style and then clear it, but rather take advantage of the WPF Framework's binding engine power. You would also not have to group/ungroup the fields to reinitialize the CellValuePresenter.
You can use an attached property which you can bind to. The attached property will point to the field that you wish to highlight.
I am attaching a small project that demonstrates this issue.
Hope this helps.