自定义自定义工具提示WPF / Silverlight

时间:2013-04-12 15:33:06

标签: c# wpf silverlight xaml tooltip

我有一个自定义的工具提示样式很好,但是,在某些情况下,我希望能够隐藏箭头(路径部分)或以不​​同方式定位工具提示。我怎样才能实现这一点以及如何在实践中设置它? 99%的时间工具提示是通过XAML& amp;绑定但偶尔会使用代码和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>

2 个答案:

答案 0 :(得分:0)

您可以启用这些控件。

<Path Margin="10,-0.5,0,0" Fill="#e5323232" Data="M 0 0 L 6 6 L 12 0 Z"/>

答案 1 :(得分: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;

        }

希望这会对你有所帮助。

相关问题