Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'ToolTip' cannot have a logical or visual parent

Tags:

wpf-controls

I have the following problem. I keep getting 'ToolTip' cannot have a logical or visual parent error when i try to style tooltip for the toggle button. What went wrong? When i take out the tooltip control under ToggleButton.ToolTip it works !

 <ToggleButton x:Name="toggle" OverridesDefaultStyle="True" Template="{StaticResource ExpanderToggleButton}" Margin="0,4,0,0" VerticalAlignment="Top" IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
     <ToggleButton.ToolTip>
         <ToolTip Style="{StaticResource tooltipstyle}">                        
             <TextBlock Background="Transparent"/>                                                                                                                      
         </ToolTip>
     </ToggleButton.ToolTip>
 </ToggleButton>
like image 463
user1163205 Avatar asked Feb 09 '12 15:02

user1163205


1 Answers

If you write code like this using property element syntax, you call already the constructor of the ToolTip class.

<ToggleButton.ToolTip>
    <TextBlock></TextBlock>                                                 
</ToggleButton.ToolTip>

There is no need to instantiate another ToolTip inside like this...

 <ToggleButton.ToolTip>
     <ToolTip Style="{StaticResource tooltipstyle}">                        
         <TextBlock Background="Transparent"/>                                                                                                                      
     </ToolTip>
 </ToggleButton.ToolTip>

Besides, on my system (using .NET 4.5) there is no error. It seems that WPF can handle both versions meanwhile as intended by the developer.

like image 156
Martin Avatar answered Oct 18 '22 07:10

Martin