Click here to Skip to main content
15,891,248 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi ,

I am trying to read a property in the tooltip in xaml to decide whether or not to show it.
However the property I am binding to does not binds does not read it .

Here's the code snippet:

<pre><ListView x:Name="myListView" Width="530" Height="234"  
                  SelectionChanged="myListView_SelectionChanged">

            <ListView.ItemContainerStyle>
                <Style TargetType="{x:Type ListViewItem}">
                    <Setter Property="ToolTip">
                        <Setter.Value>
                            <UniformGrid Columns="1">
                                <TextBlock >
                                    <TextBlock.Text>
                                        <MultiBinding StringFormat="{}{0}{1}{2}">
                                            <Binding Source="name" />
                                            <Binding Source=" :" />
                                            <Binding Path="Name" TargetNullValue="unknown"/>
                                        </MultiBinding>
                                    </TextBlock.Text>
                                </TextBlock>
                                </TextBlock>
                                <TextBlock DataContext="{Binding PlacementTarget.DataContext}" Visibility="{Binding Path= TooltipVisibility, RelativeSource={RelativeSource self} , Converter={StaticResource BooleanToVisibilityConverter}}">
                                    <TextBlock.Text>
                                        <MultiBinding StringFormat="{}{0}{1}{2}">
                                            <Binding Source="" />
                                            <Binding Source=" :" />
                                            <Binding Path="ShowCapacity" TargetNullValue="unknown"/>
                                        </MultiBinding>
                                    </TextBlock.Text>
                                </TextBlock>
                            </UniformGrid>
                        </Setter.Value>
                    </Setter>
                </Style>
            </ListView.ItemContainerStyle>
            <ListView.View>


What I have tried:

I tried to set the property and making it true or false from the code behind however changes are not reflected back.
The class's other properties are read but when try to read inside the tooltip it does not.
Posted
Updated 23-Jan-21 18:47pm
v2

1 solution

The tooltip doesn't inherit the DataContext from the parent control. The solution is to bind its DataContext to its PlacementTarget's DataContext:
XAML
<Style TargetType="{x:Type ListViewItem}">
    <Setter Property="ToolTip">
        <Setter.Value>
            <ToolTip DataContext="{Binding PlacementTarget.DataContext, RelativeSource={RelativeSource Self}" Visibility="{Binding TooltipVisibility, Converter={StaticResource BooleanToVisibilityConverter}}">
                ...
 
Share this answer
 
Comments
iampradeepsharma 24-Jan-21 0:46am    
this too is not working .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900