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 jfjuliet,
The attached ChangeCellBackgroundAtRuntime sample application contains the fullsolution implementation to your question - "How to change the background of a particular cell in the xamDataGrid ( by C# code) ?".If you have any questions, please let me know.
Best Regards,Yanko
Thanks for the information in these posts. I am using the XamDataGrid and handling the CellUpdated event. In my handler I am doing this:#
CellValuePresenter.FromCell(e.Cell).Background = Brushes.Yellow;
At first glance, this seems to work but if I scroll down I can see other cells that have been assigned the Yellow color. When I set a breakpoint I do not see the handler called for these additonal cells that get updated and turned Yellow. Seems strange. Any ideas?
Thanks.
Robert
Hi Yanko,
Thanks for this sample.. Helped me a lot!!
Regards,
Poornima
ymanolov said: 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 . ....
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 .
....
Although at first a good solution, it creates a big memory leak, since the control refers to the cell, and the cell contains the control ... A better approach is to use an attached property that you set to true when records come into view, using an override for OnRecordsInViewChanged. In Xaml you can then act on this attached property eg using a multibinding converter.
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.
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.
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?"