0

I have a treeview. It's bound to an ObservableCollection called Nodes. The bound data on the tool tips is not showing:

<controls:TreeViewEx BorderThickness="0"
                        ItemsSource="{Binding Nodes}"
                        SelectedItemEx="{Binding SelectedTreeNode, Mode=TwoWay}">

        <controls:TreeViewEx.ToolTip>

            <Grid>

                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <Image Grid.Row="0"
                        Grid.Column="0" 
                        Source="/FMG.UI.WPF;component/Media/Images/job_128.png"
                        Height="16"
                        Width="16"/>

                <TextBox Grid.Row="0"
                            Grid.Column="1"
                            Text="Job: "
                            FontWeight="Bold"/>

                <TextBox Grid.Row="0"
                            Grid.Column="2"
                            Text="{Binding ToolTipHeader}"/>

                <Border Grid.Row="1"
                        Grid.Column="0"
                        Grid.ColumnSpan="3"
                        Height="2"
                        BorderBrush="Gray"/>

                <TextBox Grid.Row="2"
                            Grid.Column="0"
                            Grid.ColumnSpan="3"
                            Text="{Binding ToolTipDetails}"/>

            </Grid>

        </controls:TreeViewEx.ToolTip>

</controls:TreeViewEx>

The tooltip pops up, but the ToolTipHeader and and ToolTipDetails are blank. The Output window says it can't find them on the view model. How do I make the binding look on the Node, not the view model?

H.B.
  • 166,899
  • 29
  • 327
  • 400
CoderForHire
  • 121
  • 1
  • 11
  • 35

1 Answers1

0

You probably want to move the code; use the TreeView.ItemContainerStyle and add a Setter for the ToolTip, this will set a node-level tool-tip.

e.g.

<controls:TreeViewEx.ItemContainerStyle>
    <Style TargetType="controls:TreeViewItemEx"> <!-- Guessing at item type name here -->
        <Setter Property="Tooltip">
            <Setter.Value>
                 <!-- Move your tooltip here -->
            </Setter.Value>
        </Setter>
    </Style>
</controls:TreeViewEx.ItemContainerStyle>

Of course the DataContext for all the bindings in the tooltip will be the current item, if you want the context of the tree-view specify a RelativeSource that finds it (also prepend "DataContext" on the Path, otherwise you bind to properties directly on the tree-view).

H.B.
  • 166,899
  • 29
  • 327
  • 400