Expander.IsExpaned only if current template is a descendant of a ToolTip

164 views Asked by At

I am using a DataTemplate (a StaticResource) in several places in my application as in an ItemsControl, ContentControl and in a ToolTip.

The template contains an Expander, and I want its IsExpanded property to be true if the DataTemplate is located within a ToolTip.

Any recommendations?

1

There are 1 answers

0
Shimmy Weitzhandler On BEST ANSWER

This checks for the parent tooltip, if there is no parent tooltip, it will be evaluated to nothing = false:

<Expander Name="expJobContacts" 
    IsExpanded="{Binding IsVisible, 
        RelativeSource={RelativeSource Mode=FindAncestor, 
            AncestorType={x:Type ToolTip}}, 
        Mode=OneTime}" />

I tested and it works.