Issue with dependency properties

Topics: fixed
Apr 21, 2009 at 8:53 AM
hi,when I write the code as follows:

            GreenButton.SetValue(ToolTipService.ToolTipProperty, "1111");
            GreenButton.SetValue(ToolTip.ShowDurationProperty, 30);
            GreenButton.SetValue(ToolTip.InitialDelayProperty, 1);
            //GreenButton.SetValue(ToolTip.ContentProperty, "1111");

it doesn't work.only xaml is supported or something I wrote wrong.
thanks.
Apr 21, 2009 at 10:34 AM
Hi, thx for the very useful reply!

To point you in a good direction, below you can find 2 examples of code that should do the trick:


//EXAMPLE 1

redToolTip =

new ToolTip {Content = "1111"};

 

redToolTip.SetValue(

ToolTip.ShowDurationProperty, 30);

 

redToolTip.SetValue(

ToolTip.InitialDelayProperty, 1);

 

RedButton.SetValue(

ToolTipService.ToolTipProperty, redToolTip);

 


//EXAMPLE 2

redToolTip =
new ToolTip{ InitialDelay = 0, ShowDuration = int.MaxValue, Content = "This is a persistent ToolTip."};

 

 

ToolTipService.SetToolTip(RedButton, redToolTip);

 


 

What went wrong in your code, is the fact that you are trying to change the ToolTip's properties by setting the value of it's dependency properties onto a button.
In a new release (very soon), I'll catch this with a proper error stating that you should only set the value of the ToolTip dependency properties on a ToolTip object.

Personally, I prefer example 2 as it is easier to understand what you are doing.
Example 1 will be supported in the next release (I'll reply here when I released the fix for this).

Did this solve your question in a sufficient way?
Again thx for the remark, and feel free to ask any further questions or post any new remarks.

Xavier Decoster

Apr 21, 2009 at 10:35 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Apr 21, 2009 at 10:51 AM
fixed in release v1.2
Apr 27, 2009 at 7:03 AM
thanks for your great job,I will try this.
hope this can be solved in silverlight 3.
what's more,where are you from?you work in Microsoft?