Click here to Skip to main content
15,939,960 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
I have a property in my user control of type Label.
Problem is if I want to set the value of the properties of this label from a host application xaml then how can it be achieved. Not able to find the correct syntax.

C#
public Label TestProperty
        {
            get { return lblValue; }
            set { lblValue = value; }
        }

in the code behind we can access this value as
C#
object.TestProperty.FontSize = 25;

how can I set the same value from the host application xaml.
Posted

You should implement this as a Dependency Property[^]
 
Share this answer
 
Comments
Versatile49 11-Apr-12 9:50am    
But then how to set the value of the font size for that label from a xaml. I am still unable to figure that out. Kindly excuse for my naivete
I beleive the following will help. What you need I beleive is a DependencyObject. The DependencyObject can then have DependencyProperties:
http://www.developer.com/net/net/article.php/3648811/Meet-DependencyObject-and-DependencyProperty-the-NET-Data-Binding-Boosters.htm[^]
I looked into this before, and could not figure how to solve your problem. I just bypassed the problem by creating specific properties.
 
Share this answer
 
Comments
Versatile49 12-Apr-12 2:13am    
Well the link talk about the dependency properties and data binding. Here I want to update a property of a label exposed using a property. Still have no clue as to how can I achieve it.
Clifford Nelson 12-Apr-12 19:04pm    
Yes, after thinking about it some more, I do not think this will work because I am sure that TestProperty is a dependency object already. I am not sure what you want to do can be done without a lot of work. I know my frustration with doing something where I wanted to set properties for buttons that were part of a control.

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