Hi,
I've presenting a very large data-set within a XamGrid, each line has different display style and I'm using conditional formatting to do so.
I'm setting all conditional formatting via code after some long loading process.
My problem is that once user selects a row, the style of the row becomes the default style of a selected-row, where the conditional formatting is lost.
I would like the conditional formatting to stay, even when user selects row, and just show a border around the row, make the font bold or any other small appearance change that will let the user know row is selected while keeping the conditional formatting as is?
this is the relevant part of conditional formatting - using a dictionary to create all types of styles
/// <summary> /// /// </summary> /// <param name="sourceDataObject"></param> /// <param name="sourceDataValue"></param> /// <returns></returns> protected override Style EvaluateCondition(object sourceDataObject, object sourceDataValue) { LogViewerLineInfo lvli = sourceDataObject as LogViewerLineInfo;
if (!_styles.ContainsKey(lvli.DisplayAttributes)) _styles.Add(lvli.DisplayAttributes, CreateStyleFromDisplayAttributes(lvli.DisplayAttributes));
return _styles[lvli.DisplayAttributes]; }
private Style CreateStyleFromDisplayAttributes(EOILogViewerDisplayAttributes eOILogViewerDisplayAttributes) { Style style = new Style(typeof(ConditionalFormattingCellControl)); style.Setters.Add(new Setter() { Property = ConditionalFormattingCellControl.ForegroundProperty, Value = new SolidColorBrush((Color)ColorConverter.ConvertFromString(eOILogViewerDisplayAttributes.ForegroundColor)) }); style.Setters.Add(new Setter() { Property = ConditionalFormattingCellControl.BackgroundProperty, Value = new SolidColorBrush((Color)ColorConverter.ConvertFromString(eOILogViewerDisplayAttributes.BackgroundColor)) }); style.Setters.Add(new Setter() { Property = ConditionalFormattingCellControl.VerticalAlignmentProperty, Value = VerticalAlignment.Center }); return style; }
Hello eligazit,I have investigated your issue, and I have asked our engineering staff to examine this further. To ensure that it will receive attention, I have logged this behavior in our internal tracking system with a Development ID of 229120. This will be assigned to a developer in a future sprint to review my investigation and confirm my findings or to offer a fix, or other resolution.Please let me know if you need more information.
Sincerely,Radko KolevSenior Software Developer
Hi, so this is a bug?
when you say 'future sprint' does it mean days, weeks or months...?
In the meanwhile, a workaround for me would be that only one column will be marked as selected rather than the entire row, how can I do that (without changing the selection mode to 'cells')?
Hello eligazit, Thank you for your feedback. I am very glad that you have manage to resolve the issue. If you require any further assistance, please do not hesitate to ask.
Excellent! exactly what I needed.
my customer will be very very happy with this (you would not believe how much...)!
Thanks.
Hello eligazid,
I have looked at your code and it looks like the problem is when you are setting the Style.BasedOn property:EmptyStyle.BasedOn = new Style(typeof(ConditionalFormattingCellControl));With the above code you are setting a new style instance to the BasedOn property and not the instance defined as static resource in the theme. Basically you need to pass the static resource style from the theme to the code where you create the style used for the selection. I am attaching a modified sample which shows how you can do it.
If you require any further assistance, please do not hesitate to ask.
Hi. thank you for your answer.
I've tried using your example and it works fine when I use the pre-defined conditional formatting object (such as LessThanConditionalFormatRule)
however, when I use custom conditional formatting class, which what I have to do as the data is created via code and so is the formatting rule (created by user at run-time), the behavior remains the same - the background becomes the default blue instead of just a border like the other cells.
I've attached the modified project - you can see that the 'salary' column is fine, as it uses the LessThanConditionalFormatRule as the conditional formating rule.
however, columns Name and Email are not ok, as they are using custom class for cond' formating (I've tried both adding the class in xaml or in code behind, behavior is the same).
Please advise.
Thanks!
Our development team reviewed the issue and have come to the conclusion that the requested functionality is currently possible, but you need to base your conditional style on the ConditionalFormattingCellControl type. I am attaching an application which demonstrates how it is possible to have a conditional formatting style and also redefining the default selection style to a red border.
The sample is having the modified xamGrid's theme in the "generic.shared.xaml" file and the original in the "generic.shared.original.xaml" file for convenience (and comparisons). The modified theme contains the following changes in the style targeting the ConditionalFormattingCellControl type:
- commenting the storyboard for the "MouseOver" visual state (to remove the light blue background when hovering a cell with the mouse)- commenting the "ObjectAnimationUsingKeyFrames" element in the "Selected" visual state to remove the light blue background from the selected rows- changing the border to top and bottom in the "ObjectAnimationUsingKeyFrames" element in the "Selected" visual state- changing the border to top and bottom in the "ObjectAnimationUsingKeyFrames" element of the "Active" visual state- changing the border brush of the Border with name "ActiveSelected" to a red solid color brush
As mentioned above another important detail is to create your custom style based on the ConditionalFormattingCellControl type. For example:<Style TargetType="{x:Type ig:ConditionalFormattingCellControl}" BasedOn="{StaticResource {x:Type ig:ConditionalFormattingCellControl}}"> <Setter Property="Background" Value="Orange" /></Style>