Hello Community!
I have an app where the theme could be changed during the runtime. At the moment the themes "Metro", "MetroDark", "IGTheme" and "OfficeBlue" are used. A customer now complained that the color of the selected XamDataGrid rows is hard to detect and he wishes a better contrast if the "OfficeBlue" theme is used.
As far I have followed the discussions about theming, I think the color in request is found in the ThemesOffice2010Blue Assemly at Themes\Office2010bluexamgrid.xaml. There I found the key "CellItemSelectedBackgroundBrush" with the color "Color_029" as entry. The theme is changed trough the TemeManager.
As I do not want to affect any other of the themes I would like to change the setting in the themes assembly. Is this possible? Or is there a other way to change the background color if the office2010blue theme is selected??
Hi grubarec,
I have been looking into your issue and what I can suggest is to create dynamically a style for DataRecordCellArea and alter the BackgroundActive/BackgroundSelected property in it when changing also the theme. I have attached sample how to do that in which I am changing both the activation and selection color for the Office2010Blue theme.
I hope this helps. If you have any further questions do not hesitate to ask.
Thanks,TeodorSoftware Developerwww.infragistics.com/support
Hello Teodor!
Thank you for the example.
As the solution I am working on consits of ~25 assemblies where the XamDatagrid is used in several views I would have to change the setters on each grid separately. Do you know of another solution approach for my problem?
I tried something like this:
Style findStyle = (Style)Application.Current.FindResource(typeof(DataRecordCellArea)); if(findStyle != null) { Setter backgroundSelectedSetting = null; foreach (Setter item in findStyle.Setters) { if(item.Property.Name == "BackgroundSelected") { backgroundSelectedSetting = item; break; } } if(backgroundSelectedSetting != null) { findStyle.Setters.Remove(backgroundSelectedSetting); findStyle.Setters.Add(new Setter(DataRecordCellArea.BackgroundSelectedProperty, new SolidColorBrush(Color.FromRgb(188, 195, 229)))); } }
But this code leads to an exception in my solution because the resource directory is already sealed and modifications are no longer possible.Thank you for your help.
Hello grubarec,
The DataRecordCellArea style which you are trying to get in the Application is sealed after the compilation so you can't modify it. The solution here is to work on Application level if you are using the xamDataGrid in multiple views. So you should add the new style like this:
if (Application.Current.Resources[typeof(DataRecordCellArea)] != null)
{
Application.Current.Resources.Remove(typeof(DataRecordCellArea));
}
var theme = (ThemesEnum)e.AddedItems[0];
switch (theme)
case ThemesEnum.Metro:
ThemeManager.ApplicationTheme = new MetroTheme();
break;
case ThemesEnum.MetroDark:
ThemeManager.ApplicationTheme = new MetroDarkTheme();
case ThemesEnum.Ig:
ThemeManager.ApplicationTheme = new IgTheme();
case ThemesEnum.Office2010Blue:
ThemeManager.ApplicationTheme = new Office2010BlueTheme();
Style newStyle = new Style();
newStyle.TargetType = typeof(DataRecordCellArea);
newStyle.Setters.Add(new Setter(DataRecordCellArea.BackgroundSelectedProperty, new SolidColorBrush(Colors.Blue)));
Application.Current.Resources.Add(typeof(DataRecordCellArea), newStyle);
default:
If you have more questions feel free to ask. Sincerely,Teodor
Hi grubarec,I am just checking whether you need further assistance on this matter.Sincerely,Teodor