Use list property in propertyGrid with AutoGeneratingPropertyDefinition = true

7 posts, 0 answers
  1. Anton
    Anton avatar
    7 posts
    Member since:
    Jan 2013

    Posted 25 Jan 2013 Link to this post

    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.
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 28 Jan 2013 Link to this post

    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.

  3. UI for WPF is Visual Studio 2017 Ready
  4. Anton
    Anton avatar
    7 posts
    Member since:
    Jan 2013

    Posted 28 Jan 2013 Link to this post

    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.

  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 28 Jan 2013 Link to this post

    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.

  6. Anton
    Anton avatar
    7 posts
    Member since:
    Jan 2013

    Posted 28 Jan 2013 Link to this post

    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)

  7. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 28 Jan 2013 Link to this post

    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.

  8. Anton
    Anton avatar
    7 posts
    Member since:
    Jan 2013

    Posted 28 Jan 2013 Link to this post

    Thank you soo much. I'll try it tommorow.
Back to Top
UI for WPF is Visual Studio 2017 Ready