2010-04-05 2 views
2

В XAML под подсказкой правильно привязывается к RelativeSource Self. Тем не менее, я не могу за жизнь мне работать, как получить TextBlock в комментировал блоке для обозначения SelectedItem.DescriptionWPF - простой относительный путь - FindAncestor

<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> 

Я бы признателен за любые предложения

Спасибо - Джереми

ответ

1

Относительный источник self означает текущий объект, который будет сам TextBox в данном конкретном случае. Вам нужен относительный источник поиска предка с типом предка RadComboBoxWithCommand. С другой стороны, и, возможно, немного проще, чтобы дать поле со списком имя и использовать ELEMENTNAME в вашем связывании вместо относительного источника:

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

к сожалению, это не работает, ни с помощью FindAncestor. Однако после немного большего количества исследований я нашел эту статью http://blogs.msdn.com/tom_mathews/archive/2006/11/06/binding-a-tooltip-in-xaml.aspx. Вам нужно привязать к PlacementTarge. –

3

кажется, что с ToolTip не имеет родителя, вы должны связать к цели размещения, как показано ниже:

<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> 

Надеется, что это полезно для кого-то Джереми

Смежные вопросы