0

我有一个自定义的工具提示样式,效果很好,但是,在某些情况下,我希望能够隐藏箭头(路径部分)或以不​​同的方式定位工具提示。我怎样才能做到这一点,我将如何在实践中进行设置?99% 的时间工具提示是通过 XAML 和绑定设置的,但有时它们是使用代码和ToolTipService

<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">
        <StackPanel>
          <Border CornerRadius="3"
                  HorizontalAlignment="Center"
                  VerticalAlignment="Top"
                  Padding="10,7"
                  BorderThickness="0"
                  Background="#e5323232">
            <StackPanel>
              <TextBlock FontFamily="Arial"
                         FontSize="12"
                         Text="{TemplateBinding Content}"
                         Foreground="#f0f0f0" />
            </StackPanel>
          </Border>
          <Path Margin="10,0,0,0"
                Fill="#e5323232"
                Data="M 0 0 L 6 6 L 12 0 Z" />
        </StackPanel>
      </ControlTemplate>
    </Setter.Value>
  </Setter>

  <Setter Property="Placement"
          Value="Top" />
  <Setter Property="HorizontalOffset"
          Value="-8" />
  <Setter Property="VerticalOffset"
          Value="0" />
</Style>
4

2 回答 2

0

您也许可以打开这些控件。

<Path Margin="10,-0.5,0,0" Fill="#e5323232" Data="M 0 0 L 6 6 L 12 0 Z"/>
于 2013-04-12T16:50:22.150 回答
0

我想在动态位置显示工具提示,所以我找到了以下解决方案。首先,我添加了一个用户控件“SimplePopupContent”作为

public partial class SimplePopupContent : UserControl
    {
        public SimplePopupContent(string value)
        {
            InitializeComponent();
            textBlockPopUp.Text = value;
        }

        private void LayoutRoot_MouseLeave(object sender, MouseEventArgs e)
        {
            this.Visibility = Visibility.Collapsed;
        }
    } 

我想显示文本块的工具提示。

TextBlock t = new TextBlock();
Popup simplePopup = new Popup();

我已经在文本块的鼠标输入事件上编写了代码

t.MouseEnter += (s, args) =>
                            {    
                                this.simplePopup.Child = new SimplePopupContent("Hi");
                             this.simplePopup.Margin = new Thickness(XOffset ,70, 0,0);
                              this.simplePopup.Width = 30;
                                this.simplePopup.Child.MouseLeave += new MouseEventHandler(Child_MouseLeave);
                                this.simplePopup.IsOpen = true;
                            };

public void Child_MouseLeave(object sender, MouseEventArgs e)
        {           
           this.simplePopup.IsOpen = false;

        }

希望这会帮助你。

于 2013-04-18T14:54:02.640 回答