I know this has been asked a million times, but I haven't been piece together anything that works.
- Coloring cell by cell, not per row
- Fields created in code
- Colors dynamic
A selector didn't seem to do the trick, because simply setting the style erases all other things I set when building the fields.
I've done other binding through triggers, but that was for a single state (bold/not bold), something like
trig.Binding =
new Binding("DataItem.Changed");
trig.Value =
false;
trig.Setters.Add(
new Setter(XamNumericEditor.FontWeightProperty, FontWeights.Normal));
style.Triggers.Add(trig);
trig =
new DataTrigger();
true;
new Setter(XamNumericEditor.FontWeightProperty, FontWeights.Bold));
What I'd like to do is bind to a property on my DataItem that returns a Brush, or should I create a bunch of triggers on a, say, int property with individual Brush values?
Or does anyone have a better idea?
Using a converter (IValueConverter) to bind the Visibility property of the CheckBox and the Background of the cellvaluepresente does not work? Have you tried that?
I want to the hide the checkbox when I change my background to gray -- what do I need to do to make this happen? I have the gray background, just can't find a way to hide the checkbox for that cell.
That works like a charm in a test project.
Alas, the event doesn't fire in the application I need it in -- obviously, I'm doing something else wrong in this massive form, but that's not your problem.
It should be A LoadCompletedEvenntHandler or smth like that.
You'll get it going a lot faster from the xaml like so:
<Window.Resources> <Style TargetType="{x:Type igDP:CellValuePresenter}"> <EventSetter Event="Loaded" Handler="cvp_Loaded"/> </Style></Window.Resources>
And in the code behind:
void cvp_Loaded(object sender, RoutedEventArgs e) { CellValuePresenter cvp = (sender as CellValuePresenter); if (cvp.Field.Name == "Age") { cvp.Background = Brushes.Red; } }
Petar.
Sounds like a plan. Question #543782548 though (are you sick of me yet?)... I have this in my window's constructor, but the event never fires -- what am I doing wrong?
EventManager.RegisterClassHandler(typeof(CellValuePresenter), CellValuePresenter.LoadedEvent, new RoutedEventHandler(PresenterLoaded), true);
Handler sig