i am having the following code:
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Style x:Key="{x:Type ToolTip}" TargetType="{x:Type ToolTip}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToolTip}">
<Border Background="Black">
<TextBlock FontFamily="Tahoma" FontSize="11" Text="{TemplateBinding Content}" Foreground="WhiteSmoke" Padding="2" />
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<StackPanel>
<Label Content="Label 1" ToolTip="asd" />
<Label Content="Label 2" ToolTip="" />
<TextBlock Text="TextBlock 1" ToolTip="asd" />
<TextBlock Text="TextBlock 2" ToolTip="" />
<Button Content="Button 1" ToolTip="asd" />
<Button Content="Button 2" ToolTip="" />
</StackPanel>
现在,您可以通过测试发现,当鼠标悬停在Label 2、Textblock 2和Button 2上时,仍会显示提示框。 我希望如果Tooltip为空或null,则不会触发它的显示。我知道我可以简单地从XAML中删除它,但我正在这里尝试一些不同的方法。
我已经尝试添加一个触发器来检查value =“”和null,并在触发器内将模板设置为null,但它们都没有起作用。
如果您中的一些专家能够为此提供一些帮助,我将非常高兴。