Property Control Enable/Disable Problem in User Control

Grids for WPF Forum

Posted 10 years ago by Balaram Barange
Version: 4.5.0487
Avatar
We have developed WPF custom control application whose task to load properties from XML file. Loading is done through “PropertyGridPropertyItem” using ActiProControl.Properties.Add(…) method.

In custom control, for each “PropertyGridPropertyItem” we have handled event called
propertyGridItem.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(propertyGridItem_PropertyChanged);

When property change occurs, we need to enable & disable some other properties. So, we have those property item’s index & set IsEnable = true and IsReadOnly = false. But it doesn’t change their state. For temporary we need to call ActiProControl.Refresh() function to get desired effect. BUT IT FLICKERS THE SCREEN THAT WE DON’T WANT. Can you please provide solution for that?

If I do the same thing in WPF application & direct using ActiPro Properties control instead of our User control it works FINE.

Comments (5)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
The IsEnabled property won't have any effect, as the PropertyGridPropertyItem is only used in the "data layer". The presentation of the properties is actually performed by a PropertyGridDataAccessorItem. We have a TODO item to look into hooking up IsEnabled and/or Visibility, so you can set those properties on the PropertyGridPropertyItem.

Changes to the IsReadOnly should be reflected in the UI, you are using the latest maintenance release (v4.5.0487). Earlier versions would not immediately update the UI with changes to IsReadOnly. So please double check that you have the latest version.

I'm not sure why it would work outside a UserControl, and not inside a UserControl. If you can send over a small sample project to our support address, then we can probably find the difference.


Actipro Software Support

Posted 10 years ago by Balaram Barange
Avatar
Thanks for the reply.

The IsReadOnly property works fine with following example. But if I add ComboBox using DataTempate and press button1 it still allow user to modify ComboBox value. Can you please suggest?
PropertyGridPropertyItem item = new PropertyGridPropertyItem();
                item.DisplayName = "Simple";
                item.Description = "Test";
                item.Value = "MyValue";
                propGrid.Properties.Add(item as IPropertyDataAccessor);

//Click on button

private void button1_Click(object sender, RoutedEventArgs e)
        {
            ((PropertyGridPropertyItem)propGrid.Properties[0]).IsReadOnly = true;
        }
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You would need to do one of two things:

1. Bind the ComboBox.IsEnabled property to the IPropertyDataAccessor.IsReadOnly property (using our BooleanNotConverter, to flip the boolean value).

2. Present the value using a TextBlock (or TextBox with IsReadOnly set to true) when IPropertyDataAccessor.IsReadOnly is true. When false, you would show the ComboBox like normal.


Actipro Software Support

Posted 10 years ago by Balaram Barange
Avatar
Please modify our sample code as per option 1. (1. Bind the ComboBox.IsEnabled property to the IPropertyDataAccessor.IsReadOnly property (using our BooleanNotConverter, to flip the boolean value).
)

Follwoing is our sample code:

private void Init9()
        {
            PropertyGridPropertyItem item = new PropertyGridPropertyItem();
            item.DisplayName = "Combo Property";
            item.Category = "General Properties";
            item.Description = "Description of combobox type";
            item.Category = "General Description";
            item.Value = "1";

            List<string> cb = new List<string>();
            cb.Add("1");
            cb.Add("2");
            cb.Add("3");

            DataTemplate dataTemplate = new DataTemplate();
            FrameworkElementFactory cmbBox = new FrameworkElementFactory(typeof(ComboBox));
            cmbBox.SetValue(ComboBox.ItemsSourceProperty, cb);
            cmbBox.SetBinding(ComboBox.IsEnabledProperty, new Binding("IsReadOnly") { RelativeSource = new RelativeSource() { AncestorType = typeof(IPropertyDataAccessor) } });

            dataTemplate.VisualTree = cmbBox;
            item.ValueTemplate = dataTemplate;
            this.propGrid.Properties.Add(item);
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            ((PropertyGridPropertyItem)propGrid.Properties[0]).IsReadOnly = true;
        }
Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
You would add "Converter = new BooleanNotConverter()" to your IsEnabled binding statement, like so:
cmbBox.SetBinding(ComboBox.IsEnabledProperty, new Binding("IsReadOnly") { RelativeSource = new RelativeSource() { AncestorType = typeof(IPropertyDataAccessor) }, Converter = new BooleanNotConverter() });


Actipro Software Support

The latest build of this product (v2019.1 build 0681) was released 9 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.