How to disable the expandred button

3 posts, 1 answers
  1. rui
    rui avatar
    54 posts
    Member since:
    May 2014

    Posted 25 Sep Link to this post

    In my program,  some time i need to disable some propertyDefinition, when the  propertyDefinition has NestedProperties, i also need disable the expand to prevent user open or close the expander

    i try to set the IsEnable propetry as this code

     var expanderButtons= myRadPropertyGrid.ChildrenOfType<RadToggleButton>().Where(b => b.Name == "PART_NestedPropertiesButton").ToList();
                expanderButtons.ForEach(t => t.IsEnabled = false);

    it is ok at the beginning but when in the case as follows is not 

    1.when close or open the properties group;

    2.when call the NestedProperties.Reset() method

    3. when  switch the propertyGrid to another one and then switch back

    it seems  this method can't be done after the second render

    how to achieve this?

    thank you

  2. Answer
    Dilyan Traykov
    Admin
    Dilyan Traykov avatar
    603 posts

    Posted 28 Sep Link to this post

    Hello rui,

    There are two approaches I can suggest for your particular scenario:

    1) To handle the FieldLoaded event of the control in a similar fashion:

    private void Pg_FieldLoaded(object sender, Telerik.Windows.Controls.Data.PropertyGrid.FieldEventArgs e)
    {
        var propertyDefinition = e.Field.DataContext as PropertyDefinition;
        if (propertyDefinition.HasNestedProperties && propertyDefinition.IsReadOnly)
        {
            e.Field.ChildrenOfType<RadToggleButton>().FirstOrDefault(b => b.Name == "PART_NestedPropertiesButton").IsEnabled = false;
        }
    }

    2) To modify the default control template of the PropertyGridField element and add a binding to the RadToggleButton's IsEnabled property pointing to its parent's IsReadOnly property.

    For your convenience, I've attached a sample project demonstrating both approaches. Please let me know if any of them works for you.

    Regards,
    Dilyan Traykov
    Progress Telerik
    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.
  3. rui
    rui avatar
    54 posts
    Member since:
    May 2014

    Posted 29 Sep in reply to Dilyan Traykov Link to this post

    Hello Dilyan,

    Great! the second is a perfect solution 

    thank you very much

Back to Top