This is a migrated thread and some comments may be shown as answers.

Collection Editor - How to change the Label Column Width in xaml?

5 Answers 486 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Iron
Joel asked on 12 Sep 2016, 10:07 AM

Hi,

  The Collection Editor is part of RadPropertyGrid defined below:
   

<telerik:RadPropertyGrid x:Name="grdTestProperty"
                         Item="{Binding TestProperty, Mode=OneWay}"
                         SearchBoxVisibility="Collapsed"
                         SearchInNestedProperties="False"
                         FieldIndicatorVisibility="Collapsed"
                         IsVirtualizing="False"
                         AutoGeneratePropertyDefinitions="True"
                         NestedPropertiesVisibility="Visible"
                         LabelColumnWidth="150"                                 
                         RenderMode="Hierarchical"
                         IsReadOnly="{Binding IsReadOnly, Mode=OneWay}"/>

   Please see attached picture showing the desired output.

 

5 Answers, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 13 Sep 2016, 01:04 PM
Hello Joel,

I'm attaching a sample project to demonstrate how you can achieve the desired behavior.

Please have a look at it and let me know whether such an approach would be suitable for you.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Joel
Top achievements
Rank 1
Iron
answered on 14 Sep 2016, 12:42 AM

Hi Dilyan,

  After applying the AutoColumnWidthBehavior, the PropertyGrid inside the CollectionEditor is showing acceptable Label Column Width behavior. However, the Items listbox width is also increased - which is not desirable. Please see attached screenshot.
It could be caused by the following Grid ColumnDefinition in CollectionEditor_Template.

<Grid Background="Transparent">
   <Grid.ColumnDefinitions>
   <ColumnDefinition Width="2*"/>
   <ColumnDefinition Width="3*"/>
</Grid.ColumnDefinitions>

  Is there any way to just change the Label Column Width of the PropertyGrid without affecting the Item width?

 

0
Joel
Top achievements
Rank 1
Iron
answered on 14 Sep 2016, 01:03 AM

Hi Dilyan,

private static void PropertyGrid_Loaded(object sender, RoutedEventArgs e)
{
    Application.Current.Dispatcher.BeginInvoke((Action)(() =>
    {
        var propertyGrid = sender as RadPropertyGrid;
        double maxWidth = 0;
        var propertyDefinitions = propertyGrid.ChildrenOfType<PropertyGridField>().ToList();
 
        foreach (var item in propertyDefinitions)
        {
            var label = item.ChildrenOfType<TextBlock>().Where(x => x.Name == "PART_FieldLabelN").First();
            maxWidth = Math.Max(label.DesiredSize.Width, maxWidth);
        }
 
        propertyGrid.LabelColumnWidth = new GridLength(Math.Max(maxWidth, propertyGrid.LabelColumnWidth.Value));
 
        //var collectionEditor = propertyGrid.ParentOfType<CollectionEditor>();
        //if (collectionEditor != null)
        //{
        //    collectionEditor.Width += maxWidth;
        //}
    }), DispatcherPriority.Background);
}

 

I have commented out the collectionEditor.Width assignment.

It is causing the collection editor to increase its width indefinitely every time it is loaded.

The Label Column Width is behaving as expected now.

 

0
Accepted
Dilyan Traykov
Telerik team
answered on 14 Sep 2016, 07:44 AM
Hello Joel,

I do apologize for neglecting this undesired effect. Replacing the code from my previous reply with the snippet below should result in the expected behavior:

private static void PropertyGrid_Loaded(object sender, RoutedEventArgs e)
{
    Application.Current.Dispatcher.BeginInvoke((Action)(() =>
    {
        var propertyGrid = sender as RadPropertyGrid;
        double maxWidth = 0;
        var propertyDefinitions = propertyGrid.ChildrenOfType<PropertyGridField>().ToList();
 
        foreach (var item in propertyDefinitions)
        {
            var label = item.ChildrenOfType<TextBlock>().Where(x => x.Name == "PART_FieldLabelN").First();
            maxWidth = Math.Max(label.DesiredSize.Width, maxWidth);
        }
 
        var collectionEditor = propertyGrid.ParentOfType<CollectionEditor>();
        if (collectionEditor != null && propertyGrid.LabelColumnWidth.Value != maxWidth)
        {
            collectionEditor.Width += maxWidth;
        }
         
        propertyGrid.LabelColumnWidth = new GridLength(Math.Max(maxWidth, propertyGrid.LabelColumnWidth.Value));
 
    }), DispatcherPriority.Background);
}

I hope this works for you.

Regards,
Dilyan Traykov
Telerik by Progress
Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
0
Joel
Top achievements
Rank 1
Iron
answered on 15 Sep 2016, 06:19 AM
Perfect!
Tags
PropertyGrid
Asked by
Joel
Top achievements
Rank 1
Iron
Answers by
Dilyan Traykov
Telerik team
Joel
Top achievements
Rank 1
Iron
Share this question
or