Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What is the difference between AmbientValueAttribute and DefaultValueAttribute in c# winform? I find that they are used to set default values, and feel that the presence of AmbientValueAttribute is superfluous.

What I have tried:

I've seen the source code for Microsoft's winform control library and can't tell the difference.
Posted
Updated 28-Jul-23 4:56am
v2

1 solution

 
Share this answer
 
Comments
Member 14475436 27-Jul-23 11:42am    
This example doesn't show the use of AmbientValue at all, only the use of DefaultValue.
Richard MacCutchan 27-Jul-23 12:31pm    
Yes it does, read it again.
Member 14475436 29-Jul-23 1:20am    
I looked at the annotation and explained that the visual designer uses the AmbientValueAttribute Attribute attribute to determine the value of the attribute to keep. Is it my understanding that an environment attribute must be AmbientValueAttribute? Because I'm writing a new environment attribute that works fine without the AmbientValueAttribute annotation. There is also Microsoft official Control library source code Control.cs BackColor, and ForeColor are environmental attributes but not marked with this feature, while the Font environment attribute is marked AmbientValue(null). My question is when exactly is the AmbientValueAttribute used?
Richard MacCutchan 29-Jul-23 3:41am    
Sorry, I have not used this attribute so do not know the answer.
Member 14475436 27-Jul-23 11:46am    
In this example, DefaultValue has done the default value function, and following the parent property change has been implemented in the get accessor of AlertForeColor. What is AmbientValue used for

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900