如何在输入WPF中的特定文本时显示组合框上的工具提示 [英] how to show tooltip on combobox when particuler text in Entered WPF

查看:89
本文介绍了如何在输入WPF中的特定文本时显示组合框上的工具提示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我正在使用WPF



我的问题是



i wamt pop /显示工具提示当特殊情况文本在组合框中输入



hi i am using WPF

my question is

i wamt pop/Show tooltip when particulaer text is entered in combo box

   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







以上代码显示工具提示,但基本没有气球等





i有另一个在xaml中设计的代码



但问题是当我输入特殊文本时我无法显示它














Above code is Showing tooltip but its basic no balloons etc


i have another code which is designed in xaml

but the issue is i cant show it When particuler text is Entered





<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>







以上代码显示组合框鼠标悬停工具提示







请帮助!!




above code shows tooltip on combobox mousehover



Please Help!!

推荐答案

仅当用户使用鼠标悬停在控件上时,才会显示工具提示。您正在滥用工具提示控件。



创建一个带有字符串并返回Visibility的值转换器。在显示警告的文本​​框附近添加标签或其他内容。将visibility属性绑定到文本框的text属性(使用元素绑定)并将值转换器添加到绑定。然后,当框中的文本与转换器查找的文本匹配时,标签将变为可见。
Tooltips are meant to be shown only when a user hovers over the control with the mouse. You are misusing the tooltip control.

Create a value converter that takes a string and returns a Visibility. Add a label or something close to your text box that presents the warning. Bind the visibility property to the textbox's text property (using an element binding) and add the value converter to the binding. Then, when the text in the box matches what your converter is looking for, the label will become visible.


这篇关于如何在输入WPF中的特定文本时显示组合框上的工具提示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆