Hi
I have managed to work out (thanks to examples) how to change a cells background, and other properties based on data trigger. Conditional formatting etc...
I have an unbound field that displays an image. Based on a cell value I wish to either change the image or change the cellValuePresenterStyle to point to another style. For example is cell value = x then use cellpresenterstyle x, if y then use cellpresenterstyle y
The code looks messy in this here but no so if you take it out and into VS
I have this xaml for the unbound field:
="UserImage1">
="Template">
>
}">
="50">
="Center"
="Top"
="50"/>
="UserImage">
}" />
This is how I manage my changes to the foreground and background properties:
winUsers()
{
InitializeComponent();
Title =
;
xamDataCarousel1.DataSource = GetUsers().DefaultView;
xamDataCarousel1.FieldLayoutInitialized +=
>(xamDataCarousel1_FieldLayoutInitialized);
}
e)
//Get the CarName field
];
//Create the style in code behind
));
//Create DataTrigger
();
//Create a Setter
.Red);
.White);
//Create a Binding
);
//Set the trigger properties
trigger1.Value =
trigger1.Binding = binding;
//Add the setter in the trigger
trigger1.Setters.Add(setter1);
trigger1.Setters.Add(setter2);
//Add the trigger in the style
s.Triggers.Add(trigger1);
idField.Settings.CellValuePresenterStyle = s;
Hello,
I think it would be best to change the source of the Image inside the CVP rather than changing the whole style. You can do this by creating triggers inside the control template which will change the Source property of the Image with setters. If you want to do this in code ,you would have to Template bind the Source property of the Image to some other property outside the template - for example Record.Tag, or the CVP, or the Value of the Cell. By changing this value, the source of the image will change accordingly.
Hi, i have a similar problem, when i change the value of the cell, i call the
CellUpdated EventIn this event, i will set a new CellValuePresenter, but in my Grid it isn´t affected to the cell. Any Idea?Here is my code:void presenter_CellUpdated(object sender, CellUpdatedEventArgs e){ if (e.Field.Label.Equals("thefield")) { Style bla = SchemaPresenter.FindResource("ManualCellChangedStyle") as Style; e.Field.Settings.CellValuePresenterStyle = bla; } }