【发布时间】:2011-12-15 20:08:45
【问题描述】:
我查看了数十个问答,但还没有找到这个看似简单的需求的答案。
我正在使用 Silverlight 4。我想在具有样式定义的 ResourceDictionary 文件中定义一个带有控件的工具提示。
我的用户控制文件“UC_Activity.xaml”有:
...
<TextBox Style="{StaticResource Style0}" Name="tb_id" />
...
如果我的“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>
但它不起作用。它构建正常,但在开始执行时会出现异常(“值不在预期范围内。”)。
请问,我该怎么做? 非常感谢。
【问题讨论】:
标签: xaml silverlight-4.0 styles tooltip