ExtZGholson
Topic Author
Posts: 22
Joined: 12 Mar 2021, 01:24

Initialize DependencyProperty when declaring component?

28 Jan 2022, 01:54

Hello,

I am currently have a component that we declare by doing the following:
<components:BasicUI
      x:Name="BasicUIBackground"
      BackVisible="False"
      CenterText="Insert Text Here"
      PrivacyVisible="False" />
BackVisible is an NsProp bool and the CenterText is a Noesis::String.

I would like to be able to be able to bind these values on our view in some cases while giving a explicit value in other cases.

In that case, we would have both
"Example A"
<components:BasicUI
      x:Name="BasicUIBackground"
      BackVisible="False"
      CenterText="Insert Text Here"
      PrivacyVisible="False" />
and
"Example B"
<components:BasicUI
      x:Name="BasicUIBackground"
      BackVisible="{Binding signup.isOnConsole}"
      CenterText="{Binding Descriptor}"
      PrivacyVisible="True" />
In order to bind it, we would need to utilize the DependencyProperty. However, I believe that the value of the DependencyProperty is set to the default value when we try to use the explicit declaration in Example A.
data->RegisterProperty<bool>(dpBackVisible, "BackVisible", Noesis::PropertyMetadata::Create(bool(true)));
This code would make Back Visible even in Example A.

Am I going about this the wrong way or do we have a suggestion on how to do this?

Thank you,

Zane
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Initialize DependencyProperty when declaring component?

28 Jan 2022, 11:25

Hi Zane, as you mentioned only DependencyProperties can be used for bindings so you should use them in that scenario.
The default value of a dependency property is only used if the value is not set from any other source (explicit local value, style setter, trigger setter...).
In example A, as you are locally setting the value of the property, that will be the effective value used, not the default one. Isn't that working for you as expected?
 
ExtZGholson
Topic Author
Posts: 22
Joined: 12 Mar 2021, 01:24

Re: Initialize DependencyProperty when declaring component?

28 Jan 2022, 19:30

Thank you, it does seem to work in some cases and in another case it just seems inconsistent. Allow me to see if I can isolate when and why it doesn't respect the properties.
 
ExtZGholson
Topic Author
Posts: 22
Joined: 12 Mar 2021, 01:24

Re: Initialize DependencyProperty when declaring component?

29 Jan 2022, 00:24

It appears that everything is working as intended. Thanks again!
 
User avatar
sfernandez
Site Admin
Posts: 3363
Joined: 22 Dec 2011, 19:20

Re: Initialize DependencyProperty when declaring component?

31 Jan 2022, 10:56

Ok, thanks for the confirmation.

Who is online

Users browsing this forum: No registered users and 2 guests