|
I'm stuck here guys. I could really use another pair of eyes on this.
I have a treeview. It's bound to an ObservableCollection<treenode> 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?
Thanks
If it's not broken, fix it until it is
modified 28-Jan-13 23:04pm.
|
|
|
|
|
Hi Kevin,
what is the DataContext of the ToolTip?
Because the bindings look at e.g. DataContext.ToolTipHeader .
Have a look at what Karl Shifflett did here: http://karlshifflett.wordpress.com/2007/12/29/wpf-sample-series-data-binding-in-tooltip/[^]
If you change <controls:TreeViewEx.ToolTip> to:
<controls:TreeViewEx.ToolTip>
<ToolTip DataContext="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Self}}">
<Grid></Grid>
</ToolTip>
</controls:TreeViewEx.ToolTip>
And change the binding of the textbox to e.g. Text="{Binding SelectedItemEx.ToolTipHeader}"
then it should work, if SelectedItemEx has the property ToolTipHeader .
But you realize that you define a tooltip for the whole treeview control and not for each treeview node, right?
Of course, if the tooltip has already as datacontext your viewmodel then Text="{Binding SelectedTreeNode.ToolTipHeader}"
should work too (without setting the ToolTip DatContext=...) stuff.
Bye,
Thomas.
|
|
|
|