CategoryEditor' DisplayName localization

Docking/MDI for WPF Forum

The latest build of this product (v25.1.2) was released 1 month ago, which was before this thread was created.
Posted 1 month ago by Procam
Version: 25.1.2
Avatar

Hello, I have this property grid and want to localize the displayed header (DisplayName) using Binding but it is not possible because it is not a DependencyProperty. Then how can I achieve this header in the property grid to be localized/translated in similar way like in my user controls below?

                <grids:CategoryEditor Category="General inputs" DisplayName="General inputs">
                    <grids:CategoryEditor.Properties>
                        <grids:CategoryEditorProperty PropertyName="Name" />
                        <grids:CategoryEditorProperty PropertyName="Label" />
                    </grids:CategoryEditor.Properties>
                    <grids:CategoryEditor.EditorTemplate>
                        <DataTemplate>
                            <Grid Grid.IsSharedSizeScope="True">
                                <ItemsControl>
                                    <propertyGrid:GridTextBox Label="{translation:Translate PatternName}" PropertyPath="{Binding Children[Name].Name}" SelectedValue="{Binding Children[Name].Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" IsReadOnly="True"/>
                                    <propertyGrid:GridTextBox Label="{translation:Translate PatternLabel}" PropertyPath="{Binding Children[Label].Name}" SelectedValue="{Binding Children[Label].Value, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
                                </ItemsControl>
                            </Grid>
                        </DataTemplate>
                    </grids:CategoryEditor.EditorTemplate>
                </grids:CategoryEditor>

Thanks for the answer!

Comments (3)

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Some of those classes are plain CLR objects and are not controls or dependency objects themselves.  Therefore, as you saw, they don't have dependency properties.

There are several options to localize this:

1) Create the CategoryEditor totally in code-behind, using localized strings for those properties.

2) Keep the CategoryEditor in XAML, but set those string properties in code-behind, using localized strings.

3) Create or use a third-party markup extension that can pull in the resources and apply that in XAML.  While we haven't tried it ourselves, here is one possible library option for a markup extension.


Actipro Software Support

Posted 1 month ago by Procam
Avatar

I found this in your sample:

				<grids:CategoryEditor Category="Colors" DisplayName="ColorsX" Description="Edit multiple Color properties using a single category editor.">
					<grids:CategoryEditor.Properties>
						<grids:CategoryEditorProperty PropertyType="Color" />
					</grids:CategoryEditor.Properties>
					<grids:CategoryEditor.EditorTemplate>
						<DataTemplate>

Even I changed DisplayName to ColorsX, there in the UI still appears Colors (the Category):

		[Category("Colors")]
		[Description("The background color.")]
		public Color BackgroundColor {
			get {
				return this.backgroundColor;
			}
			set {
				if (this.backgroundColor != value) {
					this.backgroundColor = value;
					this.NotifyPropertyChanged("BackgroundColor");
				}
			}
		}


I thought the DisplayName overrides the UI text but it does not happen. And I realize now that it changes only the text on the bottom part of the property grid, what is for me not important. So, to redefine my question: how to change the text that appears in the collapsable headers in the property grid? I know that this Category in xaml is related to the attribute in the class property as stated in the above C# code.

Posted 1 month ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Yes the collapsible headers are generated for categories.  If you use DisplayAttribute instead of CategoryAttribute on your properties, you can set the DisplayAttribute.GroupName to control the category.  DisplayAttribute allows you to create localizable text, whereas CategoryAttribute does not, so it's probably what you want to use here.  You'd just have to make sure that if you use category editors, your CategoryEditor.Category property value is updated to whatever localized category text is applied to the properties and it all should work.


Actipro Software Support

Add Comment

Please log in to a validated account to post comments.