views:

369

answers:

2

In the XAML below the ToolTip correctly binds to RelativeSource Self. However, I can't for the life of me work out how to get the TextBlock in the commented block to refer to SelectedItem.Description

<Controls:RadComboBoxWithCommand x:Name="cmbPacking"
                                 Grid.Row="2"
                                 Grid.Column="5"
                                 ItemsSource="{Binding PackingComboSource}"
                                 DisplayMemberPath="DisplayMember"
                                 SelectedValuePath="SelectedValue"
                                 SelectedValue="{Binding ElementName=dataGrid1, Path=SelectedItem.PackingID}"
                                 ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem.Description}"
                                 IsSynchronizedWithCurrentItem="True"
                                 Style="{StaticResource comboBox}">
 <!--                    <Controls:RadComboBoxWithCommand.ToolTip>-->
                <!--                        <TextBlock Text="{Binding RelativeSource={RelativeSource Self}, Path=SelectedItem.Description}" TextWrapping="Wrap" Width="50"/>-->
 <!--                    </Controls:RadComboBoxWithCommand.ToolTip>-->                   
</Controls:RadComboBoxWithCommand>

I would appreciate any suggestions

Thanks - Jeremy

A: 

A relative source of self means the current object, which would be the TextBox itself in this particular case. You want a relative source of find ancestor with an ancestor type of RadComboBoxWithCommand. Alternatively, and perhaps a little simpler, is to give the combo box a name and use ElementName in your binding instead of a relative source:

<ComboBox x:Name="cb" ...>
    <ComboBox.ToolTip>
        <TextBlock Text="{Binding SelectedItem.Description, ElementName=cb}" .../>

HTH,
Kent

Kent Boogaart
Unfortunately this doesn't work, nor using FindAncestor. However, after a bit more research I found this article http://blogs.msdn.com/tom_mathews/archive/2006/11/06/binding-a-tooltip-in-xaml.aspx. You need to bind to the PlacementTarge.
Jeremy Holt
+1  A: 

It seems that since ToolTip does not have a parent, you need to bind to the placement target as below:

<Controls:RadComboBoxWithCommand Grid.Row="2"
                                             Grid.Column="5"
                                             ItemsSource="{Binding PackingComboSource}"
                                             DisplayMemberPath="DisplayMember"
                                             SelectedValuePath="SelectedValue"
                                             SelectedValue="{Binding ElementName=dataGrid1, Path=SelectedItem.PackingID}"
                                             IsSynchronizedWithCurrentItem="True"
                                             Style="{StaticResource comboBox}">
                <Controls:RadComboBoxWithCommand.ToolTip>
                    <ToolTip DataContext="{Binding RelativeSource={RelativeSource Self}, Path=PlacementTarget}">
                        <TextBlock Text="{Binding SelectedItem.Description}"
                                   TextWrapping="Wrap"
                                   Width="100" />
                    </ToolTip>
                </Controls:RadComboBoxWithCommand.ToolTip>
            </Controls:RadComboBoxWithCommand>

Hope this is useful for someone Jeremy

Jeremy Holt