Just opened to the wisdom of the "WPF" in the style Set ToolTip blog post, although eventually gave a temporary solution to the problem, but did not analyze and explain the problem, It is with him: But as for why it is not possible to place TextBlock directly in Setter.value is an unsolved mystery.
Take advantage of the noon gap, followed a bit, here I will give you a complete analysis.
To describe the problem, first of all, to the problematic XAML, of course, you can also go to the sage's blog to view the detailed description.
<textblock x:name= "Textblockcontainer" text= "ABC" margin= "ten" >
<!--The following wording is not a problem-->
<!--< tooltipservice.tooltip>
<textblock
text= "//Get text from somewhere by binding"
textwrapping= "Wrap"
width= " />
</ToolTipService.ToolTip>-->
<!--use style to assign values to TOOLTIP, error! Will throw exception-->
<TextBlock.Style>
<style targettype= "TextBlock" >
<setter property= "Tooltipservice.tooltip" >
<Setter.Value>
<textblock x:name= "Tooltipblock"
text= "//Get the text from somewhere by binding,"
textwrapping= "Wrap"
width= "/>
</Setter.Value>
</ setter>
</Style>
</TextBlock.Style>
</TextBlock>
The information for the exception is:
Exception
System.Windows.Markup.XamlParseException occurred
message= "Cannot add content of type" System.Windows.Controls.TextBlock ' to an object of type ' System.Object '. Error at object ' System.Windows.Controls.TextBlock ' in markup file ' Wpfapplication1;component/window1.xaml ' line 17 Position. "
Source= "PresentationFramework"
linenumber=17
lineposition=30
namecontext= "Value"
stacktrace: At
System.Windows.Markup.XamlParseException.ThrowException (String message, Exception innerexception, Int32 LineNumber, Int32 lineposition, Uri BaseUri, Xamlobjectids currentxamlobjectids, Xamlobjectids contextxamlobjectids, Type objectType) innerexception: