How can the category name be dynamically switched?
I need to switch between multiple languages.
However, it was found that the category names could not be refreshed in real time.
Parameter names and parameter descriptions are acceptable.
please help me . Thank you.
private void PropertyGrid_PreparePropertyItem(object sender, Xceed.Wpf.Toolkit.PropertyGrid.PropertyItemEventArgs e)
{
if (e?.PropertyItem is not PropertyItem propertyItem) return;
PropertyDescriptor? propertyDescriptor = propertyItem.PropertyDescriptor;
if (propertyDescriptor == null)
return;
ApplyPropertyItemLocalization(propertyItem, propertyDescriptor);
}
private static void ApplyPropertyItemLocalization(PropertyItem propertyItem,PropertyDescriptor propertyDescriptor)
{
LocalizedDisplayNameAttribute? displayNameAttribute =propertyDescriptor.Attributes[typeof(LocalizedDisplayNameAttribute)]as LocalizedDisplayNameAttribute;
if (displayNameAttribute != null)
{
propertyItem.DisplayName =LocalizationResourceHelper.GetString(displayNameAttribute.ResourceKey,displayNameAttribute.ResourceKey);
}
LocalizedDescriptionAttribute? descriptionAttribute =propertyDescriptor.Attributes[typeof(LocalizedDescriptionAttribute)]as LocalizedDescriptionAttribute;
if (descriptionAttribute != null)
{
propertyItem.Description =LocalizationResourceHelper.GetString(descriptionAttribute.ResourceKey,descriptionAttribute.ResourceKey);
}
LocalizedCategoryAttribute? categoryAttribute =propertyDescriptor.Attributes[typeof(LocalizedCategoryAttribute)]as LocalizedCategoryAttribute;
if (categoryAttribute != null)
{
propertyItem.Category =LocalizationResourceHelper.GetString(categoryAttribute.ResourceKey,categoryAttribute.ResourceKey);
}
}
private void RefreshPropertyGrid()
{
object? oldObject = GlobalPropertyGrid.SelectedObject;
if (oldObject == null)
return;
TypeDescriptor.Refresh(oldObject);
TypeDescriptor.Refresh(oldObject.GetType());
GlobalPropertyGrid.SetCurrentValue(PropertyGrid.SelectedObjectProperty, null);
Dispatcher.BeginInvoke(new Action(() =>
{
TypeDescriptor.Refresh(oldObject);
TypeDescriptor.Refresh(oldObject.GetType());
GlobalPropertyGrid.SetCurrentValue(PropertyGrid.SelectedObjectProperty, oldObject);
GlobalPropertyGrid.UpdateLayout();
GlobalPropertyGrid.Update();
}), DispatcherPriority.ContextIdle);
}
How can the category name be dynamically switched?
I need to switch between multiple languages.
However, it was found that the category names could not be refreshed in real time.
Parameter names and parameter descriptions are acceptable.
please help me . Thank you.
private void PropertyGrid_PreparePropertyItem(object sender, Xceed.Wpf.Toolkit.PropertyGrid.PropertyItemEventArgs e)
{
if (e?.PropertyItem is not PropertyItem propertyItem) return;
}
private static void ApplyPropertyItemLocalization(PropertyItem propertyItem,PropertyDescriptor propertyDescriptor)
{
LocalizedDisplayNameAttribute? displayNameAttribute =propertyDescriptor.Attributes[typeof(LocalizedDisplayNameAttribute)]as LocalizedDisplayNameAttribute;
}
private void RefreshPropertyGrid()
{
object? oldObject = GlobalPropertyGrid.SelectedObject;
}