views:

34

answers:

2

Hi,

I've created a simple UserControl in ExpressionBlend. The UserControl is a ractangle with a TextBlock in it. When i use this UserContol in a Silverlight project, i can not change the text in the textBlock of the control. Should give an acces to the TextBlock before using the Control?

HELP"_

+1  A: 

Your user control should have public properties that map to its features. If you want the users of the control to be able to set the text, create a Text property. The implementation can be as simple as forwarding to the inner TextBox. Exposing the inner control is not the right way to do it.

Timores
OK...so should I do it like this:public string PublicProductName{ get { return (String)GetValue(this.ProductName.Text); } set { { SetValue(this.ProductName.Text, value); } }}??Is it OK?
Rafal
What are GetValue and SetValue in your context ? DependencyObject.GetValue ? If yes, you don't need them. Just return or set ProductName.Text.
Timores
public String PublicProductName { get { return this.ProductName.Text; } set { this.ProductName.Text = PublicProductName.ToString(); } }I think this does not work at all...:(
Rafal
And here is how i Use this controll and how i'm trying ot set the content:<leaf:MainControl Name="firstLeaf" PublicProductName="shdaksflahsdgkfjahsgdkfjhgasdh"></leaf:MainControl> </controls:TreeViewItem>
Rafal
OK ....i've found the error:) it should not be: set { this.ProductName.Text = PublicProductName.ToString()BUT: set { this.ProductName.Text = value}
Rafal
A: 

I use only GetValue and SetValue...and I'm getting an error. I think i need DependencyProperty...or am I wrong?

Rafal
Additional info should be added by editing your question. Please edit your question and delete this answer.
AnthonyWJones