# We think, EnabledIf attribute have UI refresh issue

**URL:** <https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230>\
**Category:** Technical\
**Tags:** bug\
**Created:** [February 16, 2021, 9:31am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230 "2021-02-16T09:31:00Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![justin\_c\_i](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/justin_c_i/32/232_2.png) [@justin\_c\_i](https://forum.opentap.io/u/justin_c_i)\
**Post date:** [February 16, 2021, 9:31am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/1 "2021-02-16T09:31:00Z")

</div>

Hi Team,

We think **EnabledIf** attribute have an UI refresh issue, if the value is set also , it is not reflected in the UI in some cases.

_Let me explain,_

I have a combo box, which is of KindOfLimits (ENUM) type

```
 public KindOfLimits Kinds
        {
            get { return this.kinds; }
            set
            {
                this.kinds = value;
                this.OnPropertyChanged(nameof(this.Kinds));             
               
            }
        }

```

I have an custom control (IControlProvider) which will be enabled only if **KindOfLimits== NominalTolerance and AssignVaribaleFrom==UserInput**.

```
[ConvertToArrayViewIfCanAttribute(nameof(Tolerance), nameof(DataTypeSelected))]
[EnabledIf(nameof(AssignVaribaleFrom), AssignmentType.UserInput, HideIfDisabled = true)]
[EnabledIf(nameof(Kinds), KindOfLimits.NominalTolerance, HideIfDisabled = true)]
[Display("Check", Order: 0.1)]
public string Tolerance
{
    get;set;
}

```

_**About our custom control(ConvertToArrayViewIfCanAttribute)**_:  
Depending on the datatype selected custom control will display a textbox or a combobox.

_ **Problem we face :** _  
For the first time when we assign value to **Kinds** and **AssignVaribaleFrom**. UI is not updated.  
When we click on another test step and come back then UI will be okay.

_ **Work Around we do:** _  
if we do the following way then it is okay.

> Task.Run(() =\>  
> {  
> Thread.Sleep(200);  
> this.OnPropertyChanged(nameof(this.Tolerance));  
> });

eg:

```
    public KindOfLimits Kinds
    {
        get
        {
            return this.kinds;
        }
        set
        {
            this.kinds = value;
            this.OnPropertyChanged(nameof(this.Kinds));

            Task.Run(() =>
            {
                Thread.Sleep(200);
                this.OnPropertyChanged(nameof(this.Tolerance));
            });
        }
    }

```

---

<div class="post-metadata">

**Author:** ![brennen\_direnzo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/brennen_direnzo/32/6_2.png) [@brennen\_direnzo](https://forum.opentap.io/u/brennen_direnzo)\
**Post date:** [February 16, 2021, 3:27pm UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/2 "2021-02-16T15:27:44Z")

</div>

Thanks @justin_c_i . Is this something you saw where the behavior changes with a specific version of OpenTAP?

If you click out of the entry field does the UI update or does it have to be opening a different Test Step and returning?

---

<div class="post-metadata">

**Author:** ![justin\_c\_i](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/justin_c_i/32/232_2.png) [@justin\_c\_i](https://forum.opentap.io/u/justin_c_i)\
**Post date:** [February 17, 2021, 12:48am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/3 "2021-02-17T00:48:34Z")

</div>

Is this something you saw where the behavior changes with a specific version of OpenTAP? - _We tested only in 9.12._

If you click out of the entry field does the UI update or does it have to be opening a different Test Step and returning?- _If we click on the entry field then also field will get updated. we don’t need to click on another test step._

---

<div class="post-metadata">

**Author:** ![brennen\_direnzo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/brennen_direnzo/32/6_2.png) [@brennen\_direnzo](https://forum.opentap.io/u/brennen_direnzo)\
**Post date:** [February 17, 2021, 3:19am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/4 "2021-02-17T03:19:59Z")

</div>

I think this is somewhat intentional to prevent multiple updates as the input changes. It only updates when the context changes, but I can submit something to see if we can improve this behavior.

---

<div class="post-metadata">

**Author:** ![justin\_c\_i](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/justin_c_i/32/232_2.png) [@justin\_c\_i](https://forum.opentap.io/u/justin_c_i)\
**Post date:** [February 17, 2021, 3:26am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/5 "2021-02-17T03:26:05Z")

</div>

Okay, Thanks for the support. 🙂  
We use our work around for time being .

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [February 17, 2021, 8:11am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/6 "2021-02-17T08:11:52Z")

</div>

Hi Justin,

Do you see this issue when used with your IControlProvider or does it also occur for eg. a text box control?

---

<div class="post-metadata">

**Author:** ![justin\_c\_i](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/justin_c_i/32/232_2.png) [@justin\_c\_i](https://forum.opentap.io/u/justin_c_i)\
**Post date:** [February 17, 2021, 8:24am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/7 "2021-02-17T08:24:19Z")

</div>

@rolf_madsen we don’t see this issue when we use without IControlProvider.  
Becasue there is no UI change if we use without IControlProvider.

---

<div class="post-metadata">

**Author:** ![rolf\_madsen](https://avatars.discourse-cdn.com/v4/letter/r/43a26b/32.png) [@rolf\_madsen](https://forum.opentap.io/u/rolf_madsen)\
**Post date:** [February 17, 2021, 8:43am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/8 "2021-02-17T08:43:16Z")

</div>

I don’t understand, but if you can describe how to reproduce the issue in a simple way, we can probably fix it in 9.13.

---

<div class="post-metadata">

**Author:** ![justin\_c\_i](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/justin_c_i/32/232_2.png) [@justin\_c\_i](https://forum.opentap.io/u/justin_c_i)\
**Post date:** [February 17, 2021, 8:45am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/9 "2021-02-17T08:45:47Z")

</div>

I will try to create a simple custom control, and try to simulate this issue. Thanks.

---

<div class="post-metadata">

**Author:** ![david-wsd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/david-wsd/32/204_2.png) [@david-wsd](https://forum.opentap.io/u/david-wsd)\
**Post date:** [February 19, 2021, 1:34am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/10 "2021-02-19T01:34:51Z")

</div>

@justin_c_i Not sure if this will help, but it has helped me with similar issues of updating the UI from a custom IControlProvider. Try calling OnPropertyChanged from the IControlProvider (or its view model), instead of relying on the OnPropertyChanged call at the test step property level. Here’s a snippet:

```
IMemberAnnotation memAnn = annotations.Get<IMemberAnnotation>();
(annotations.Source as ValidatingObject).OnPropertyChanged(memAnn.Member.Name);
```

---

<div class="post-metadata">

**Author:** ![justin\_c\_i](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/justin_c_i/32/232_2.png) [@justin\_c\_i](https://forum.opentap.io/u/justin_c_i)\
**Post date:** [February 19, 2021, 2:03am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/11 "2021-02-19T02:03:19Z")

</div>

Hi @david-wsd ,  
I m already using something like this.

```
        public void RefreshProperty(CustomAnnotaionCollection customAnnotationMain)
        {
            try
            {
                var stringValueProvider = customAnnotationMain.baseAnnotationCollection.Get<IStringValueAnnotation>();
                (customAnnotationMain.baseAnnotationCollection.Source as TestStep).OnPropertyChanged(nameof(stringValueProvider));
            }
            catch
            {
                // Hanldes Exception
            }
        }

```

Problem I feel is like **EnabledIF** have high UI priority than the ICustomProvider.

Like, EnabledIF Property will be hidden in the UI,  
Depending on another properties only it will be visible in the UI,

When EnabledIF is displayed in the UI for the first time, it takes basic control .(Even if EnabledIF property need to display a combobx depending on customProvider, it still displays a Textbox).

When I refresh the EnabledIF property in another thread then CustomProvider control is displayed.

I feels UI rendering for **hidden** properties is occurred in the following way .  
`ICustomProvider -> EnabledIF(Which displays a Textbox always).`

I feels UI rendering for **Visible** properties is occurred in the following way .  
`EnabledIF-> ICustomProvider -> (Which displays a custom control).`

And Also if EnabledIF is rendered in the GUI once then it works normal.(then we enable or disable the EnabledIF consitions also still it works as expected,).

Only for the first time this issue have.

Thank you very much @david-wsd for the support.

Regards  
Jestin CI

---

<div class="post-metadata">

**Author:** ![david-wsd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/david-wsd/32/204_2.png) [@david-wsd](https://forum.opentap.io/u/david-wsd)\
**Post date:** [February 19, 2021, 10:42pm UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/12 "2021-02-19T22:42:01Z")

</div>

Hi @justin_c_i, cool, that looks about like what I typically do.

You said the IControlProvider is conditionally returning a combobox. Does that mean that the control provider’s CreateControl() function is checking the value of DataTypeSelected, and based on that it will either return a combobox, or null? (thereby defaulting to OpenTAP’s default textbox control provider)

---

<div class="post-metadata">

**Author:** ![justin\_c\_i](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/justin_c_i/32/232_2.png) [@justin\_c\_i](https://forum.opentap.io/u/justin_c_i)\
**Post date:** [February 20, 2021, 1:35am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/13 "2021-02-20T01:35:26Z")

</div>

Hi @david-wsd  
Does that mean that the control provider’s CreateControl() function is checking the value of DataTypeSelected, and based on that it will either return a combobox, or null?-- _Based on Datatype selected CreateControl() will return a combobox or a button_.

unfortunately for the first time a Textbox is displayed in the GUI.

---

<div class="post-metadata">

**Author:** ![david-wsd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/david-wsd/32/204_2.png) [@david-wsd](https://forum.opentap.io/u/david-wsd)\
**Post date:** [February 22, 2021, 10:20pm UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/14 "2021-02-22T22:20:22Z")

</div>

@justin_c_i Interesting. So the very first time, it’s ignoring the control you’ve created in CreateControl(), and is instead using opentap’s default textbox control.

What happens if you set EnabledIf’s HideIfDisabled to false?  
Or, what happens if you remove the EnabledIf attribute entirely?

Do either of the above modifications result in the correct control being displayed at all times?

---

<div class="post-metadata">

**Author:** ![justin\_c\_i](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/justin_c_i/32/232_2.png) [@justin\_c\_i](https://forum.opentap.io/u/justin_c_i)\
**Post date:** [February 23, 2021, 1:35am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/15 "2021-02-23T01:35:38Z")

</div>

What happens if you set EnabledIf’s HideIfDisabled to false?- _ICutomProvider works correctly._  
Or, what happens if you remove the EnabledIf attribute entirely?- _ICutomProvider works correctly._

Do either of the above modifications result in the correct control being displayed at all times? - _Yes, Then ICustomProvider works normally. Becasue we are using this custom control in 70+ Test steps and we never encountered any error like this…Only for EnabledIf we saw this first time issue_

---

<div class="post-metadata">

**Author:** ![david-wsd](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/david-wsd/32/204_2.png) [@david-wsd](https://forum.opentap.io/u/david-wsd)\
**Post date:** [February 23, 2021, 2:44am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/16 "2021-02-23T02:44:03Z")

</div>

Thanks for confirming, @justin_c_i. I agree with you, it sounds like an issue specific to the EnabledIf attribute, as your post title states.

I’m curious if CreateControl is even being called the first time.

---

<div class="post-metadata">

**Author:** ![justin\_c\_i](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/justin_c_i/32/232_2.png) [@justin\_c\_i](https://forum.opentap.io/u/justin_c_i)\
**Post date:** [February 23, 2021, 4:00am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/17 "2021-02-23T04:00:11Z")

</div>

I’m curious if CreateControl is even being called the first time.-- _Yes, I tried putting a break point in Create control… it got hit._

---

<div class="post-metadata">

**Author:** ![john.berlien](https://avatars.discourse-cdn.com/v4/letter/j/ac91a4/32.png) [@john.berlien](https://forum.opentap.io/u/john.berlien)\
**Post date:** [July 28, 2021, 3:26pm UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/18 "2021-07-28T15:26:49Z")

</div>

Hi @brennen_direnzo was there ever a resolution to this in the OpenTAP code? I’m having the same problem, where EnabledIf is applied (with HideIfDisabled is set to true) to a method in a custom Dialog, not a TestStep, but this is not updating, even when implementing INotifyPropertyChanged and using OnPropertyChanged.

---

<div class="post-metadata">

**Author:** ![brennen\_direnzo](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/brennen_direnzo/32/6_2.png) [@brennen\_direnzo](https://forum.opentap.io/u/brennen_direnzo)\
**Post date:** [July 28, 2021, 3:30pm UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/19 "2021-07-28T15:30:36Z")

</div>

@john.berlien I don’t think anything was specifically done in OpenTAP to address this. Can you create a new issue?

---

<div class="post-metadata">

**Author:** ![justin\_c\_i](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.opentap.io/justin_c_i/32/232_2.png) [@justin\_c\_i](https://forum.opentap.io/u/justin_c_i)\
**Post date:** [July 29, 2021, 1:24am UTC](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230/21 "2021-07-29T01:24:06Z")

</div>

Work Around We Do is

> Task.Run(() =\>  
> {  
> Thread.Sleep(200);  
> this.OnPropertyChanged(nameof(this.Tolerance));  
> });

**Example:**

```csharp
public KindOfLimits Kinds
    {
        get
        {
            return this.kinds;
        }
        set
        {
            this.kinds = value;
            this.OnPropertyChanged(nameof(this.Kinds));

            Task.Run(() =>
            {
                Thread.Sleep(200);
                this.OnPropertyChanged(nameof(this.Tolerance));
            });
        }
    }

```

```csharp
[EnabledIf(nameof(Kinds), KindOfLimits.NominalTolerance, HideIfDisabled = true)]
[Display("Check", Order: 0.1)]
public string Tolerance
{
    get;set;
}

```

[Next page](https://forum.opentap.io/t/we-think-enabledif-attribute-have-ui-refresh-issue/230.md?page=2)
