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

Maximal width of PropertyGrid value column on long texts

12 Answers 82 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Simon
Top achievements
Rank 1
Simon asked on 28 Jan 2017, 03:19 PM

In our application we use the autogenerate property grid fields mechanism. The property grid is located in a radpane (RadDocking) like in visual studio. The LabelColumnWidth of the property grid is set to 100px. 

We have the problem that long string values (f.i. file paths) in the property grid value column cause horizontal scrolling. Is there any possibility to disable the horizontal scrolling if the values of property fields are to long for the field?

We would like to have an autoresizing property grid. If the user increases the size of the dock the label column stays on 100px while the value column width increases to the the size: width of the RadPane - width of the column value.

That would be the behaviour I would expect.

 

Thanks and best regards,

Simon

12 Answers, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 01 Feb 2017, 01:14 PM
Hi Simon,

For your convenience, I prepared an example to demonstrate how to achieve the desired behavior. Please take a look at the implementation and consider how this approach fits your scenario.

I hope that this helps. Should you have any other questions, do not hesitate to contact us.

Regards,
Martin Vatev
Telerik by Progress
Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
0
Simon
Top achievements
Rank 1
answered on 01 Feb 2017, 02:04 PM
Thanks man, that's what I needed =)
0
Andy
Top achievements
Rank 1
answered on 22 Oct 2018, 03:52 PM
This post has helped me as well, thanks! Why not expose this as a property for the property value column? It would make this so much easier.
0
Dinko
Telerik team
answered on 25 Oct 2018, 11:26 AM
Hi Simon,

Thank you for sharing your idea. We appreciate every feedback from our customers. You are right that this functionality can be further improved. For any functionality that you find useful and we do not have it implemented in our control you can use our feedback portal to submit a feature request. Once the feature is approved everyone can vote for its implementation. By voting the priority of the item gets increased.

Regards,
Dinko
Progress Telerik
Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Reese
Top achievements
Rank 1
answered on 24 Nov 2019, 02:57 AM

I have this same problem, but when I try the sample code, I get an error message that it contains no elements.

That is, there are no children of type <VirtualizingStackPanel> my PropertyGrid.

Any ideas on how to fix that?

0
Dinko
Telerik team
answered on 27 Nov 2019, 11:02 AM

Hi Reese,

I have double-checked the attached project from my colleague Martin, but haven't got any error message. May I ask you to specify where this message error is thrown and the steps to reproduce it. Do I need to modify the project? Any additional information is highly appreciated.

Regards,
Dinko
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Reese
Top achievements
Rank 1
answered on 27 Nov 2019, 01:56 PM

Thanks for responding.

I never resolved the error, but I did find another workaround.  I first created a Data Template for the TextBox:

        <DataTemplate x:Key="TextBoxTemplate">
            <TextBox x:Name="PropertyTextBox"
                     Loaded="PropertyTextBox_Loaded"
                     HorizontalAlignment="Left"
Width="250"/>
        </DataTemplate>


And then, I added the following code to the AutoGeneratingProperty event to apply that template:

            if (e.PropertyDefinition.SourceProperty.PropertyType.Name == "String" && e.PropertyDefinition.EditorTemplate == null)
            {
                //This works along with the "TextBoxTemplate" and the PropertyTextBox_Loaded method to limit the width of the TextBox 
                DataTemplate dt = (DataTemplate)this.Resources["TextBoxTemplate"];
                e.PropertyDefinition.EditorTemplate = dt;
            }

 

Finally, I added this code to the Loaded event for the data template TextBox:

        private void PropertyTextBox_Loaded(object sender, RoutedEventArgs e)
        {
            //This works along with the "TextBoxTemplate" to limit the width of the TextBox 
            if (sender is TextBox)
            {
                TextBox tb = (TextBox)sender;
                string propertyName = ((Telerik.Windows.Controls.Data.PropertyGrid.PropertyDefinition)((PropertyGridField)tb.Parent).DataContext).AutoGeneratedPath;
                Binding b = new Binding(propertyName);
                b.Mode = BindingMode.TwoWay;
                tb.SetBinding(TextBox.TextProperty, b);
            }
        }




0
Dinko
Telerik team
answered on 28 Nov 2019, 12:11 PM

Hello Reese,

I am happy to hear that you have a workaround for this behavior and thank you for sharing it. If you have any other questions you can open a new forum thread with your questions inside.

Regards,
Dinko
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Allistair
Top achievements
Rank 1
answered on 24 Jan 2020, 12:19 PM

I get the same error as Reese.

I have not made any changes to the project and ran it, 'as is'.

Exception thrown: System.InvalidOperationException
  HResult=0x80131509
  Message=Sequence contains no elements
  Source=System.Core.

0
Dinko
Telerik team
answered on 29 Jan 2020, 10:59 AM

Hello Allistair,

Thank you for the provided error details.

I still wasn't able to reproduce this error. My guess here it comes from the different assemblies version used on your side. Can you share which version of our DLLs are you referencing? I am re-attaching the sample project with a trial version of our assemblies. This way you can just download it and run it directly. Give it a try and let me know if you reproduce this error again.

Regards,
Dinko
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Johnathan
Top achievements
Rank 1
answered on 17 Nov 2020, 01:40 PM
The v2 example the behavior that I am looking for.  I am getting the same exception as above.  I have attached a screenshot of the exception as well as the csproj snippet so you can see the libraries I am using.  I have multiple property grid, some are auto generate and some are not.  I get the same exception on both.
0
Dinko
Telerik team
answered on 20 Nov 2020, 09:08 AM

Hello Johnathan,

Thank you for the provided images.

I have double-checked the project from my previous reply, but such an exception does not appear on my side. Can you confirm that you haven't made any changes to the code inside? If you have, can you share what changes are added. Also, just for the test, can you change the DispatcherPriority inside the Loaded event to ApplicationIdle and let me know if it makes any difference.

private void PropertyGrid1_Loaded(object sender, RoutedEventArgs e)
{
	Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, new Action(() =>
	{
		(sender as RadPropertyGrid).ChildrenOfType<VirtualizingStackPanel>().First().ScrollOwner.HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled;
	}));
}

Regards,
Dinko
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
Simon
Top achievements
Rank 1
Answers by
Martin
Telerik team
Simon
Top achievements
Rank 1
Andy
Top achievements
Rank 1
Dinko
Telerik team
Reese
Top achievements
Rank 1
Allistair
Top achievements
Rank 1
Johnathan
Top achievements
Rank 1
Share this question
or