Hi,
I just want to know how to change the background colour for a particular cell in XamlGrid. I want to do this in Code behind (C#). Could anyone please assist on this.
Many thanks in advance
Florence
Hi Arthi,
You can change the background color in two ways.
One by creating a style for the CellValuePresenter of that particular cell or setting the editor's background of the CellValuePresenter to the new color. You can see all the default styles in the local directory on your computer : "~ \Infragistics\NetAdvantage for WPF 2008 Vol. 2\DefaultStyles".
Here is some source code with the Editor's Background.
DataRecord dr = xamDG.ActiveRecord as DataRecord;
CellValuePresenter cvpText = CellValuePresenter.FromRecordAndField(dr, dr.FieldLayout.Fields[0]);
XamTextEditor te = cvpText.Editor as XamTextEditor;
te.Background = Brushes.Red;
Hope this helps.
I just want to know how to change the background colour for a particular cell on loading the XamGrid itself.
I want to do this in Code behind (C#). Could anyone please assist on this.
Thanks in advance
- Arthi
Hi RobertBrower,
In answer to your question - "How can I make it so that the control remembers that the changed cell's styleeven after it is scrolled out then back into view ?" a great solution to the issue was suggested by Joe Dour and Andrew Smith. Special thanks to both of them for the suggested solution.
The solution
1. Use the Tag property on the Cell, so in the CellUpdated event set Cell.Tag to a Boolean true .2. Bind the Tag of the CellValuePresenter to a multibinding that binds to the CellValuePresenter's Field and Record to obtain the Cell and then set the CellValuePresenter style trigger to bind to the Tag.Tag(i.e. Cell.Tag) .
<Style TargetType="{x:Type igDP:CellValuePresenter}"> <Setter Property="Tag"> <Setter.Value> <MultiBinding Converter="{StaticResource fieldRecordToCell}"> <Binding RelativeSource="{RelativeSource Self}" Path="Field" /> <Binding RelativeSource="{RelativeSource Self}" Path="Record" /> </MultiBinding> </Setter.Value> </Setter> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Tag.Tag, Converter={StaticResource keepChangedCellStyle}}" Value="True" > <Setter Property="Background" Value="Yellow"/> </DataTrigger> </Style.Triggers></Style>
The attached KeepCellStyleOutOfVisibleAreaSample application contains the full implementation of the solution.
Best Regards,Yanko
Thanks for your quick response.
My goal is to highlight changed cells in yellow. I do not want the changed cells to revert back to their original color after they have been scrolled out of the visible area then back in again.
First I create a style like this:
<Style x:Key="cellChangedStyle" TargetType="{x:Type igDP:CellValuePresenter}">
<Setter Property="Background" Value="#FFFF0000" />
</Style>
Then, in the CellUpdated event handler, I set the style of the cell like this:
CellValuePresenter.FromCell(e.Cell).Style = cellChangedStyle;
The problem is that the control does not remember that I changed a cell's style after it has been scrolled out of the visible area of the control if the expander checkbox has not been clicked, then back in view again. How can I make it so that the control remembers that the changed cell's style even after it is scrolled out then back into view? If the expander checkbox is clicked again and an items children are hidden, then the expander checkbox is clicked again to show the children, the color does not show.
Additionally, I have a Save button which saves all of the changed data entities when it is clicked. At this point, then I would like to clear the styles I have set on all the changed cells so that they are no longer yellow.
Many thanks.
Robert
I would like to assist you in solving your issue.Could you please, provide me with the following:
1. Your sample application( you could attach it, if it's possible)
2. Answer to the question -" What are you trying to achieve as a final result through your application?"