当输入WPF中的特定文本时,如何在组合框上显示工具提示
当在组合框中输入特定文本时,我需要弹出/显示工具提示当输入WPF中的特定文本时,如何在组合框上显示工具提示,wpf,vb.net,xaml,combobox,Wpf,Vb.net,Xaml,Combobox,当在组合框中输入特定文本时,我需要弹出/显示工具提示 If cmbDatabase.Text.ToUpper = "TRAINING" Then Dim tool As New ToolTip() tool.Content = "Warning : You are about to log into a training database" & cmbDatabase.tooltip = tool tool.IsOpen = True end if 上面的代
If cmbDatabase.Text.ToUpper = "TRAINING" Then
Dim tool As New ToolTip()
tool.Content = "Warning : You are about to log into a training database" &
cmbDatabase.tooltip = tool
tool.IsOpen = True
end if
上面的代码显示了工具提示,但基本上没有气球等
我有另一个用xaml设计的代码
但问题是,当输入特定文本时,我无法显示它
<Window.Resources>
<Style x:Key="{x:Type ToolTip}" TargetType="ToolTip">
<Setter Property="OverridesDefaultStyle" Value="true"/>
<Setter Property="HasDropShadow" Value="True"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Border CornerRadius="7" HorizontalAlignment="Center" VerticalAlignment="Top" Padding="5" BorderThickness="3,3,3,3" >
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#CF181818" Offset="0"/>
<GradientStop Color="#BE1C1C1C" Offset="1"/>
</LinearGradientBrush>
</Border.Background>
<!--<Border.BorderBrush>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#80FFFFFF" Offset="0"/>
<GradientStop Color="#7FFFFFFF" Offset="1"/>
<GradientStop Color="#FFFFF18D" Offset="0.344"/>
<GradientStop Color="#FFFFF4AB" Offset="0.647"/>
</LinearGradientBrush>
</Border.BorderBrush>-->
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.1*" />
<ColumnDefinition Width="0.9*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<!--<Image Source="pack://application:,,,/resources/info_icon.jpg" Grid.Row="0" Grid.RowSpan="2" Grid.Column="0" Margin="3" />-->
<TextBlock FontFamily="Tahoma" Grid.Row="0" Grid.Column="1" FontSize="13" Text="{TemplateBinding Content}" Foreground="#5095D6" />
<TextBlock FontFamily="Tahoma" Grid.Row="1" Grid.Column="1" FontSize="11" Text="To expediate your process please click here" Foreground="#FFFFFFFF" />
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
上面的代码显示了组合框鼠标上方的工具提示,您可以这样尝试
<Style TargetType="ComboBox">
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Value="1">
<Setter Property="ToolTip" Value="You selected 1"/>
</DataTrigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Text}" Value="2">
<Setter Property="ToolTip" Value="U selected 2"/>
</DataTrigger>
</Style.Triggers>
</Style>
</Grid.Resources>
<StackPanel>
<Label>Hi,</Label>
<ComboBox>
<ComboBoxItem>1</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>3</ComboBoxItem>
</ComboBox>
</StackPanel>
你好
1.
2.
3.
您是否尝试使用数据触发器。我试过了,但我还是wpf新手,还不知道如何使用datatriger@Dandy您是否可以尝试实现上述Xaml。它所做的是当一些数据“1”出现在这里时,触发tootip的属性。在这里,我设置了soure RelativeSource Self和Path=Text。它需要查看的内容,当它具有条件时,它将触发setter属性。我应该把上面的代码(样式标签)粘贴进去吗。