【问题标题】:how to show tooltip on combobox when particular text in Entered WPF输入 WPF 中的特定文本时如何在组合框上显示工具提示
【发布时间】:2014-08-08 09:33:01
【问题描述】:

我想要在组合框中输入特定文本时弹出/显示工具提示

 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>

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

【问题讨论】:

  • 您尝试使用数据触发器了吗? Reference

标签: wpf vb.net xaml combobox


【解决方案1】:

你可以这样试试

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

【讨论】:

  • 我试过了,但我是 wpf 的新手,仍然不知道如何使用 datatriger
  • @Dandy 你能尝试实现上面的 Xaml 吗?它的作用是当一些数据“1”出现在这里时,它会触发 tootip 的属性。在这里 Binding 我设置了酸的 RelativeSource Self 和 Path = Text 。它需要查看的内容,当它有条件时,它会触发 setter 属性。 This will help
  • 我应该将上面的代码(样式标签)粘贴到 中吗?
猜你喜欢
  • 1970-01-01
  • 2011-07-20
  • 1970-01-01
  • 2014-02-07
  • 2019-07-01
  • 2013-12-21
  • 2012-07-17
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多