Hello,
I have below code in Window.Resources in XAML.
<Style TargetType="DataGridRow"> <Style.Triggers> <DataTrigger Binding="{Binding Name}" Value="Input"> <Setter Property="Background" Value="#7FA1C1"/> </DataTrigger>
This will set background of datagrid row to "#7FA1C1" if value of row is "Input".
This "Input" has to be localized to different languages. Say in German it may be "In1". In this case, background wont be set.
To avoid this, I remove from XAML and write below in code behind in constructor of Window after InitializeComponent().
Style style = new System.Windows.Style(typeof(DataGridRow)); DataTrigger dt = newDataTrigger { Binding = newBinding { Path = newPropertyPath("Name"), RelativeSource=RelativeSource.Self}, Value = ResourceManager.GetString("Input"),// Will get localized value from resx for each language }; dt.Setters.Add(newSetter(DataGridRow.BackgroundProperty, Color.FromRgb(127,161,193))); style.Triggers.Add(dt); this.Resources.Add(this.Resources.Count, style); grdComponentDetails.RowStyle = style;
If I run this, I am getting exception, '#FF7FA1C1' is not a valid value for the 'System.Windows.Controls.Panel.Background' property on a Setter.
Any suggestions will be helpful
Regards,
Harish
Harish