Hi,
I want to give Background Color to LabelPresenter when a
1) field with in a column is selected
2) When that particular Label Presenter is selected.
I think this needs to be done at codebehind so basically I need to know that how can we find the Label Presnter when a particulkar field is selected.
Thanks
Sumeet
here what you can do
code behind.
Style style = new Style(typeof(CellValuePresenter)); Debug.WriteLine("Creating Style"); DataTrigger trigger = new DataTrigger()
DataTrigger selectedtrigger = new DataTrigger() { Binding = new Binding("IsSelected") { RelativeSource = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(DataRecordCellArea), 1) }, Value = true }; selectedtrigger.Setters.Add(new Setter(Control.BackgroundProperty, Brushes.White)); style.Triggers.Add(selectedtrigger); xamDataGrid1.FieldSettings.CellValuePresenterStyle = style;
or in XAML
<Style TargetType="{x:Type igDP:CellValuePresenter}"> <Style.Triggers> <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type igDP:DataRecordCellArea}}, Path=IsSelected}" Value="True"> <Setter Property="Background" Value="Red" /> </DataTrigger> </Style.Triggers> </Style>
Thanks for the reply, but my requirement is setting the background color on the field header i.e. label presenter when a cell in a column is selected not setting the color on the cell value presenter.
Hello,
I am just checking if my last reply was helpful for you.
If you require any further assistance please do not hesitate to ask.
Hi Yanko,
Any chance to get the same behavior, but when the user filters for any column?. I need to change the Background color when the user filter the grid, and get the default values when the filter gets removed.
thanks in advance!
Pablo
Thank you for your feedback. I am gald that you have managed to resolve your issue.
Thank you for your post. I also was able to get the same behavior, by implementing the following code behind on the RecordFilterChange Event.
var lColor = (e.RecordFilter.Conditions.Count == 0) ? Brushes.Transparent : Brushes.CornflowerBlue;
var lp = Utilities.GetDescendantFromType(XamInactivas, typeof(LabelPresenter), false) as LabelPresenter;
var parent = lp.Parent;
var child = VisualTreeHelper.GetChild(parent, e.RecordFilter.Field.Index);
((LabelPresenter)child).Background = lColor;
thank you very much for your help.
Regards,
Thank you for your post. I have been looking into your requirement and I managed to achieve the desired behavior handling the ‘KeyUp’ and ‘LostFocus’ events of the FilterCellValuePresenter. I am attaching a sample application(DataGridColumnHeadersHighlighting.zip) that shows my approach.
Please in future create a separate forum thread for each of your new questions.
Let me know, if you need any further assistance on this matter.