工具提示显示子元素的类型,而不是子元素的内容

时间:2019-04-26 17:28:03

标签: wpf vb.net xaml tooltip

我为一个按钮创建了一个UserControl,该按钮的图像在表面延伸。我正在尝试显示该按钮的工具提示,该提示比常规的基于文本的提示更为详尽。工具提示由标题文本,上述图像的较大版本和描述文本组成。 UserControl的XAML如下...

<UserControl x:Class="AdvancedTooltipUserControl" 
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:MyProject"
             mc:Ignorable="d">
    <Button Background="#00000000" Foreground="#00000000" BorderBrush="#00000000" 
            VerticalAlignment="Center" HorizontalAlignment="Center" 
            Command="{Binding DisplayPdf}">
        <StackPanel>
            <Image Stretch="UniformToFill" Margin="1" 
                   VerticalAlignment="Center" HorizontalAlignment="Right" 
                   Source="{Binding es.ImageNo}">
                <Image.ToolTip>
                    <ToolTip>
                        <StackPanel Height="Auto" Width="250">
                            <TextBlock FontWeight="Bold" FontSize="12" 
                                       Margin="0,0,0,5" Text="{Binding es.Arrangement}"/>
                            <Image Margin="1" Stretch="Uniform" 
                                   Source="{Binding es.ImageNo}"/>
                            <Border Margin="0,8" BorderBrush="Silver" 
                                    BorderThickness="0,1,0,0"/>
                            <TextBlock TextWrapping="Wrap" 
                                       Text="{Binding es.LongDescription}"/>
                        </StackPanel>
                    </ToolTip>
                </Image.ToolTip>
            </Image>
        </StackPanel>
    </Button>
</UserControl>

当我运行该应用程序时,该按钮将按预期显示(绑定的图像覆盖其表面)。但是,当我将鼠标悬停在按钮上时,将显示一个文本工具提示,其中包含System.Windows.Controls.StackPanel,而不是StackPanel的详细内容。我已经为此进行了很长时间的搏斗,而且似乎什么也没得到解决,所以我想问问专家是否知道我要去哪里错了!

0 个答案:

没有答案
相关问题