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

How to disable the expandred button

2 Answers 590 Views
PropertyGrid
This is a migrated thread and some comments may be shown as answers.
rui
Top achievements
Rank 1
rui asked on 25 Sep 2017, 12:29 PM

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 Answers, 1 is accepted

Sort by
0
Accepted
Dilyan Traykov
Telerik team
answered on 28 Sep 2017, 10:07 AM
Hello ,

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

1) To handle the  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 you to write beautiful native mobile apps using a single shared C# codebase.
0
rui
Top achievements
Rank 1
answered on 29 Sep 2017, 12:21 PM

Hello Dilyan,

Great! the second is a perfect solution 

thank you very much

Tags
PropertyGrid
Asked by
rui
Top achievements
Rank 1
Answers by
Dilyan Traykov
Telerik team
rui
Top achievements
Rank 1
Share this question
or