Xaml 银光4号。如何在带有样式定义的ResourceDictionary文件中使用控件设置工具提示?

Xaml 银光4号。如何在带有样式定义的ResourceDictionary文件中使用控件设置工具提示?,xaml,silverlight-4.0,styles,tooltip,Xaml,Silverlight 4.0,Styles,Tooltip,我已经看了几十个问答,但还没有找到这个看似简单的需求的答案 我和Silverlight 4一起工作。我想在具有样式定义的ResourceDictionary文件中定义一个工具提示,其中包含控件 我的用户控制文件UC_Activity.xaml具有: ... <TextBox Style="{StaticResource Style0}" Name="tb_id" /> ... 如果my Styles.xaml文件 <ResourceDictionary xmlns="

我已经看了几十个问答,但还没有找到这个看似简单的需求的答案

我和Silverlight 4一起工作。我想在具有样式定义的ResourceDictionary文件中定义一个工具提示,其中包含控件

我的用户控制文件UC_Activity.xaml具有:

...
<TextBox Style="{StaticResource Style0}" Name="tb_id" />
...
如果my Styles.xaml文件

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
    <Style x:Key="Style0" TargetType="TextBox">
        <Setter Property="FontSize" Value="12" />
        <Setter Property="FontFamily" Value="Portable User Interface" />
        <Setter Property="ToolTipService.ToolTip" Value="Long tooltip text here. This WORKS, but part of the text ends up out of the screen." />
    </Style>
</ResourceDictionary>
它可以工作,但我只能显示简单的文本作为工具提示,如果文本很长,它将结束在屏幕外,在那里它是不可能被看到的。我想要的是这样的东西:

<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk">
    <Style x:Key="Style0" TargetType="TextBox">
        <Setter Property="FontSize" Value="12" />
        <Setter Property="FontFamily" Value="Portable User Interface" />
        <Setter Property="ToolTipService.ToolTip">
            <Setter.Value>
                <StackPanel>
                    <sdk:Label Content="Short text here."/>
                    <TextBlock TextWrapping="Wrap" MaxWidth="200" Text="Long text here. This does NOT WORK." />
                </StackPanel>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
但它不起作用。它生成ok,但给出的异常值不在预期范围内。开始执行时

拜托,我怎么做?
非常感谢。

我有一个类似的问题,问题是它需要是一个数据模板,因此每次使用它时都会向可视化树添加一个不同的实例。我为此创建了一个附加属性:

那么它可以按如下方式使用:

<Setter Property="ControlsBehaviours:TooltipTemplate.Template">
    <Setter.Value>
            <DataTemplate>
                <ToolTip Content="tooltip" />
            </DataTemplate>
        </Setter.Value>
    </Setter>

public class TooltipTemplate
{
    /// <summary>
    /// Template Dependency Property.
    /// </summary>
    public static readonly DependencyProperty TemplateProperty =
        DependencyProperty.RegisterAttached(
            "Template",
            typeof (DataTemplate),
            typeof (TooltipTemplate),
            new PropertyMetadata(new PropertyChangedCallback(TemplateChanged)));

    public static void SetTemplate(DependencyObject o, DataTemplate value)
    {
        o.SetValue(TemplateProperty, value);
    }

    public static DataTemplate GetTemplate(DependencyObject o)
    {
        return (DataTemplate) o.GetValue(TemplateProperty);
    }

    private static void TemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
    {
        ToolTipService.SetToolTip(d, ((DataTemplate)e.NewValue).LoadContent());
    }
}