RadPropertyGrid field width problem

2 Answers 32 Views
PropertyGrid
Igor.Antohin
Top achievements
Rank 1
Iron
Igor.Antohin asked on 11 Jan 2022, 10:51 AM
Hello. How to make the field fill the width of the container and not stretch to fit the text. Two pictures in the attachment. In the second image, the PropertyGrid extends outside the container. 

2 Answers, 1 is accepted

Sort by
0
Igor.Antohin
Top achievements
Rank 1
Iron
answered on 12 Jan 2022, 11:19 AM | edited on 12 Jan 2022, 11:22 AM

The issue has been resolved.


Loaded += LoadedHandler;
    
private void LoadedHandler(object sender, RoutedEventArgs e)
        {
            var propertyGridPresenter = this.ChildrenOfType<PropertyGridPresenter>().FirstOrDefault();
            var scrollViewer = propertyGridPresenter?.ChildrenOfType<ScrollViewer>().FirstOrDefault();
            if (scrollViewer != null)
            {
                scrollViewer.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
            }
        }
PS. But I think this it would be worth making it a separate property at the component level. 

Stenly
Telerik team
commented on 14 Jan 2022, 10:09 AM

I am glad that you have found a working solution and that you took the time to share it. Also, thank you for the provided feedback. I will look into this and try to provide an answer to this question.
0
Stenly
Telerik team
answered on 14 Jan 2022, 01:28 PM

Hello Igor,

An alternative approach you could use, instead of subscribing to the Loaded event, would be to create a Style inside the RadPropertyGrid control instance's Resources collection, with ScrollViewer as TargetType. Then set its HorizontalScrollBarVisibility property to Disabled. In addition, for the string properties with long values, you could create an additional Style with TargetType="TextBox" and set its TextWrapping property to Wrap.

The following code snippet shows this approach's implementation:

<telerik:RadPropertyGrid>
    <telerik:RadPropertyGrid.Resources>
        <Style TargetType="ScrollViewer">
            <Setter Property="HorizontalScrollBarVisibility" Value="Disabled" />
        </Style>
        <Style TargetType="TextBox">
            <Setter Property="TextWrapping" Value="Wrap" />
        </Style>
    </telerik:RadPropertyGrid.Resources>
</telerik:RadPropertyGrid>

The result is as follows:

With that said, could you give this approach a try?

Regards,
Stenly
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
PropertyGrid
Asked by
Igor.Antohin
Top achievements
Rank 1
Iron
Answers by
Igor.Antohin
Top achievements
Rank 1
Iron
Stenly
Telerik team
Share this question
or