I need to makes some changes to a ToolTip programmatically. That sounds simple enough. Well, apparently not really. :/
I have a ToolTip on a WindowsFormsHost object and I make the following cast to get to the IsOpen property:
((System.Windows.Controls.ToolTip)host.ToolTip).IsOpen = true;
This line fails during runtime with an InvalidCastException.
Unable to cast object of type ‘System.String’ to type
‘System.Windows.Controls.ToolTip’.
I don’t understand why this is failing. I must be missing some thing terribly simple as this code apparently works just fine in this example. @_@
ToolTipis not by accident of Typeobjectand notToolTip. If you set theToolTipin XAML like thisToolTip="Test"then your ToolTip is of type String. Have a look at this. To modify your tooltip, i would suggest not using it in code directly, instead use the power of XAML and DataBinding. If you insist doing it in code, create an actual ToolTip for the property.