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

Use list property in propertyGrid with AutoGeneratingPropertyDefinition = true

6 Answers 236 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
Anton
Top achievements
Rank 1
Anton asked on 25 Jan 2013, 07:59 PM
Hello.

I have some problem. I use ProperyGrid to modify object properies (I have mdi window control. And for selected window I set class A to PropertyGrid.Item in dynamic). In class A I have Prop1 and List1 of suitable values for Prop1. Prop1 is a selected value from List1. How can I display this property in ProperyGrd?

Thanks.

6 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 28 Jan 2013, 09:42 AM
Hello Anton,

You can try handling AutoGeneratingPropertyDefinition event of RadPropertyGrid and create new LookupPropertyDefinition, set its required properties and assign it to the e.PropertyDefinition.
The exact implementation depends entirely on your exact settings and requirements, but it could be something similar to:

private void OnAutoGeneratingPropertyDefinition(object sender, AutoGeneratingPropertyDefinitionEventArgs e)
        {
            var lookup = new LookupPropertyDefinition();
            lookup.ItemsSource = list1;
            .........
  
            e.PropertyDefinition = lookup;
        }
 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Anton
Top achievements
Rank 1
answered on 28 Jan 2013, 10:12 AM

Thanks for the answer. But I think I can't use this solution, because objects  are very diffrent. I use Prism and module pattern in my application. I don't want to write code in OnAutoGeneratingPropertyDefinition method, because in this context application don't know about objects.

It will be good to use DataAnnotation to resolve this problem.But I think it's impossible. Am I right?

I found solution. In every mdi window I write in XAML list of PropertyDefinitions (dependency property). And when I handle that the window is selected I add collection of propertyDefinitions to the PropertyGrid.

Thanks.

0
Maya
Telerik team
answered on 28 Jan 2013, 12:09 PM
Hello Anton,

Generally, during AutoGeneratingPropertyDefinition event, you will most probably have the information for the object and its properties. 
Nevertheless, I am happy to see that you found the most appropriate solution for your case. 

All the best,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Anton
Top achievements
Rank 1
answered on 28 Jan 2013, 12:21 PM
By the way. How I can force PropertyGrid to work faster? I add and remove propertyDefinitions in code:

///

<summary>

/// Очищает окно свойство

/// </summary>

private void ClearPropertyGrid()

{

 

if(PropertyGrid == null) return;

PropertyGrid.PropertyDefinitions.Clear();

PropertyGrid.Item =

 

null;

}

#endregion

#region

 

 

Public Methods

public void SetActiveItem(IElementWithPropertyDefinitions element)

{

 

if(Equals(element, _activeElement) || PropertyGrid == null) return;

_activeElement = element;

 

//Удалить свойства текущего окна

ClearPropertyGrid();

 

 

//Добавить свойства нового окна

 

foreach (var propertyDefinition in element.PropertyGridDefinitions)

{

     PropertyGrid.PropertyDefinitions.Add(propertyDefinition);

}

PropertyGrid.Item = control.DataContext;

}

I have only 1 property in test but I see a time delay (use dotTrace Perfomance 4.0):

22.78% - Telerik.Windows.Data.QueryableCollectionView.OnSourceCollectionChanged(Object,NotifyCollectionChangedEventArgs)
14.15% - Telerik.Windows.Controls.RadPropertyGrid.OnItemPropertyChanged(DependencyObject, DependencyPropertyChangedEventArgs)

0
Maya
Telerik team
answered on 28 Jan 2013, 04:47 PM
Hi Anton,

You can download our latest internal build where PropertyDefinitions collection is ObservableItemCollection<PropertyDefinition>. Thus you will be able to call SuspendNotifications() and ResumeNotifications() methods on updating the collection.  

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Anton
Top achievements
Rank 1
answered on 28 Jan 2013, 05:48 PM
Thank you soo much. I'll try it tommorow.
Tags
PropertyGrid
Asked by
Anton
Top achievements
Rank 1
Answers by
Maya
Telerik team
Anton
Top achievements
Rank 1
Share this question
or