Wpf 工具提示绑定时出现BindingExpression路径错误

Wpf 工具提示绑定时出现BindingExpression路径错误,wpf,binding,tooltip,Wpf,Binding,Tooltip,我在DataGridCell中使用了工具提示。 在我的项目中,我使用AvalonDock并创建了3或4个窗口选项卡。 然后,它工作得很好,工具提示在DataGrid中也显示得很好,但是当我交换选项卡时会出现错误。我认为加载程序… 这是我的.xaml代码的一部分 <DataGrid.CellStyle> <Style TargetType="DataGridCell" BasedOn="{StaticResource MetroDataGr

我在DataGridCell中使用了工具提示。 在我的项目中,我使用AvalonDock并创建了3或4个窗口选项卡。 然后,它工作得很好,工具提示在DataGrid中也显示得很好,但是当我交换选项卡时会出现错误。我认为加载程序…
这是我的.xaml代码的一部分

        <DataGrid.CellStyle>
            <Style TargetType="DataGridCell" BasedOn="{StaticResource MetroDataGridCell}">
                    <Setter Property="ToolTip" Value="{Binding Path=Content.Text, RelativeSource={RelativeSource Self}}" />
            </Style>
        </DataGrid.CellStyle>

成功了。 但也有错误表明

System.Windows.Data错误:40:BindingExpression路径错误:在“对象”“ContentPresenter”(名称=“”)上找不到“文本”属性。BindingExpression:Path=Content.Text;DataItem='DataGridCell'(名称='';目标元素是“DataGridCell”(名称=“”);目标属性为“工具提示”(类型为“对象”)

我怎样才能修好它

+添加 我修改了源代码

<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=Content}" />


然后,消除了绑定表达式错误。但DataGridCell的内容在显示工具提示(如我发布的图片)后就消失了!!奇怪的虫子

我的
工具提示是这样做的:

<Setter Property="ToolTip" Value="{Binding RelativeSource={RelativeSource Self}, Path=Content.Text}"/>

交替

工具提示样式

预览

这是我第一次尝试的。它工作正常,但也存在类似“System.Windows.Data错误:40:BindingExpression路径错误:'Text'属性未在'object''ContentPresenter'(Name='')上找到。BindingExpression:path=Content.Text;DataItem='DataGridCell'(Name='');目标元素为'DataGridCell'(Name='';目标属性为'ToolTip'(type'object')”1.谢谢你的好意回复。我修改了你的代码,然后工具提示显示良好,没有错误。但这样的DataGridCells中的内容不会显示!:(嗯…它需要显示。我怎样才能添加图片?天啊,我错了,对不起!它工作得很好!!非常感谢。:)我投你的票
<DataGrid>
    <DataGrid.Columns>
        <DataGridTemplateColumn>
            <DataGridTemplateColumn.Header>
                <TextBlock Text="Foo Header"/>
            </DataGridTemplateColumn.Header>
            <DataGridTemplateColumn.CellTemplate>
                <DataTemplate>
                    <DataTemplate.Resources>
                        <Style TargetType="{x:Type TextBlock}">
                            <Setter Property="ToolTip">
                                <Setter.Value>
                                    <ToolTip 
                                            Style="{StaticResource ToolTipBrowserDescription}" 
                                            Content="{Binding FooProperty}"
                                            HasDropShadow="True">
                                    </ToolTip>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </DataTemplate.Resources>
                    <TextBlock Text="{Binding FooProperty}" TextTrimming="CharacterEllipsis"/>
                </DataTemplate>
            </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
    </DataGrid.Columns>
</DataGrid>
<Style TargetType="{x:Type ToolTip}" x:Key="ToolTipBrowserDescription">
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ToolTip}">
                <Border BorderBrush="#FF424242" Background="#FFEEEEEE" BorderThickness="1">
                    <TextBlock Text="{TemplateBinding Content}" FontWeight="Bold" TextWrapping="Wrap" Margin="5" MinWidth="50" MaxWidth="500"/>
                    <Border.Effect>
                        <DropShadowEffect Opacity="0.65" ShadowDepth="1"/>
                    </Border.Effect>
                </Border>
                <ControlTemplate.Triggers>
                    <Trigger Property="ToolTipService.HasDropShadow" Value="True">
                        <Setter Property="Margin" Value="0,0,1,1"/>
                    </Trigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>