首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >WPF -简单相对路径- FindAncestor

WPF -简单相对路径- FindAncestor
EN

Stack Overflow用户
提问于 2010-04-06 01:47:53
回答 2查看 3.9K关注 0票数 2

在下面的XAML中,ToolTip正确地绑定到RelativeSource本身。然而,我无论如何也想不出如何让注释块中的TextBlock引用SelectedItem.Description

代码语言:javascript
复制
<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>

如果有任何建议,我将不胜感激。

谢谢- Jeremy

EN

回答 2

Stack Overflow用户

发布于 2010-04-06 05:07:43

似乎由于ToolTip没有父对象,所以需要绑定放置目标,如下所示:

代码语言:javascript
复制
<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>

希望这对某些人有用,杰里米

票数 3
EN

Stack Overflow用户

发布于 2010-04-06 02:49:06

self的相对源是指当前对象,在本例中是TextBox本身。您需要一个祖先类型为RadComboBoxWithCommand的查找祖先的相对源。或者,也许更简单的是,给组合框一个名称,并在绑定中使用ElementName,而不是相对源:

代码语言:javascript
复制
<ComboBox x:Name="cb" ...>
    <ComboBox.ToolTip>
        <TextBlock Text="{Binding SelectedItem.Description, ElementName=cb}" .../>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2579963

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档