I have a derived class, LocalizedCategoryAttribute, which extends the built-in CategoryAttribute class. This derived class overrides the GetLocalizedString property with a value pulled from a .resx file.
In the program there is a control with a built-in property, for example, FontFamily, that has been given a LocalizedCategoryAttribute with a key. This successfully returns the custom value for the LocalizedCategoryAttribute ("Fuentes de Botones" in my example). However, the control now has two category attributes - the default CategoryAttribute, and the custom LocalizedCategoryAttribute.
At the time the PropertyGrid chooses the category to place that FontFamily property in, sometimes it uses the LocalizedCategoryAttribute value ("Fuentes de Botones"), while other times it uses the CategoryAttribute value ("Appearance").
I want this to consistently always be the value from the LocalizedCategoryAttribute.
I have tried changing the order of the attributes, and even of the properties. Nothing appears to be consistent enough for me to pinpoint what is causing the use of LocalizedCategoryAttribute vs CategoryAttribute. I thought it was to do with the order, as two instances of the same control, with different conditionally shown properties would cause the built-in properties like FontFamily to show under the "Fuentes de Botones" category, while the other instance had it showing under the "Appearance" category. All non-built-in properties work every time with the LocalizedCategoryAttribute value.
LocalizedCategories.resx
The .resx file has a key "ButtonFont" and value "Fuentes de Botones"
LocalizedCategoryAttribute.cs
public class LocalizedCategoryAttribute : CategoryAttribute
{
private readonly string resourceName;
public LocalizedCategoryAttribute(string resourceName)
{
this.resourceName = resourceName;
}
protected override string GetLocalizedString(string value)
{
return LocalizedCategories.ResourceManager.GetString(resourceName);
}
}
exampleControl.cs
public class exampleControl : Control {
...
/// <summary>Gets or sets the font family of the button</summary>
[LocalizedCategory("ButtonFont")]
[LocalizedDisplayName("ButtonFontFamily")]
[LocalizedDescription("ButtonFontDescription")]
public FontFamily FontFamily
{
get { return (FontFamily)GetValue(FontFamilyProperty); }
set { SetValue(FontFamilyProperty, value); }
}
/// <summary>Gets or sets the color of the button's text</summary>
[LocalizedCategory("ButtonFont")]
[LocalizedDisplayName("ButtonTextColor")]
[LocalizedDescription("ButtonTextColorDescription")]
public Brush TextColor
{
get { return (Brush)GetValue(TextColorProperty); }
set { SetValue(TextColorProperty, value); }
}
...
}
Result The example control shows the correctly localized display names and descriptions (defined in different .resx files) for both properties, but only the custom property shows up in the PropertyGrid with the localized category. The FontFamily's category is "Appearance".