I get this runtime error:
Unable to cast object of type 'System.Windows.Controls.ToolTip' to type System.Windows.Controls.Label. I understand what that means but I'm not sure why it's happening.
when I mouse over a treeviewitem. What I want is the ToolTipOpening on a treeview item to run a method. Here is the XAML. I did this based on on this thread:
TreeViewItem Tooltip Binding Not Working
It wasn't quite my problem but it did tell me at least how to set the tooltip on a treeview item.:
<TreeView x:Name="ISLTreeView" Height="auto" Background="GhostWhite"
BorderThickness="0" Width="auto"
ItemsSource="{Binding}"
ScrollViewer.VerticalScrollBarVisibility="auto">
<TreeView.ItemContainerStyle>
<Style TargetType="{x:Type TreeViewItem}">
<Setter Property="IsExpanded"
Value="{Binding IsExpanded, Mode=TwoWay}" />
<Setter Property="ToolTip">
<Setter.Value>
<ToolTip
ToolTipOpening="ISL_TreeViewTipOpening">
</ToolTip>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsSelected" Value="True">
<Setter Property="FontWeight" Value="Bold" />
</Trigger>
</Style.Triggers>
</Style>
</TreeView.ItemContainerStyle>
</TreeView>
Here is the method, there's not much in it yet.
private void ISL_TreeViewTipOpening(object sender, ToolTipEventArgs e)
{
TreeListViewItem tvi = sender as TreeListViewItem;
}
Edited to add the next XAML code that defines a Label and another treeview
<Label x:Name="NeighborLabel" Content="Neighbors List"></Label>
<TreeView x:Name="NeighborsTreeView" Height="Auto"
Background="GhostWhite" BorderThickness="0" Width="auto"
ItemsSource="{Binding}"
ScrollViewer.VerticalScrollBarVisibility="auto">
</TreeView>