TipWindow.xaml

前半厂

<UserControl x:Class="ComputerDropDragControl.TipWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">

    <Grid x:Name="LayoutRoot" Background="White" >
        <Grid.Resources>
            <Storyboard x:Name="stortBoardOne" x:Key="storyBoardOne" Completed="stortBoardOne_Completed"></Storyboard>
        </Grid.Resources>
        <Popup x:Name="tip" MouseMove="tip_MouseMove">
            <Grid x:Name="toolTip" Width="300" Height="220" Opacity="0.8">
                <Grid.Background>
                    <ImageBrush ImageSource="Img/tipWindowOne.png"></ImageBrush>
                </Grid.Background>
                <Grid.RowDefinitions>
                    <RowDefinition  Height="auto"/>
                    <RowDefinition />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="auto"/>
                </Grid.ColumnDefinitions>
                <TextBlock Grid.Row="0" Grid.Column="0" x:Name="mainContent"
                           Foreground="Black" FontSize="14" Height="Auto" HorizontalAlignment="Left"  Margin="10,10,10,0"
                           VerticalAlignment="Top" TextWrapping="Wrap"  Width="200"/>
            </Grid>
        </Popup>
    </Grid>
</UserControl>

后半厂

using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading;

namespace ComputerDropDragControl
{
    /// <summary>
    /// 提示框
    /// 创建人:吴兆娟
    /// 创建时间:2011-11-4
    /// </summary>
    public partial class TipWindow : UserControl
    {
        #region <<页面加载>>

        /// <summary>
        /// 页面加载
        /// </summary>
        public TipWindow()
        {
            InitializeComponent();

            //定时器
            this.stortBoardOne.Duration = new TimeSpan(0, 0, 0, 2, 0);

            mainContent.Foreground = new SolidColorBrush(Colors.Black);
            mainContent.Text = "这种ToolTip是是是到nsk电脑上开始看神道贺就" + DateTime.Now.Millisecond;
        }

        #endregion

        #region <<控件事件>>

        /// <summary>
        /// “定时器完成时”发生的事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void stortBoardOne_Completed(object sender, EventArgs e)
        {

        }

        #endregion

        #region <<辅助方法>>

        public void BindControl(UIElement uc, NodeFrameView entity)
        {
            uc.MouseLeave += new MouseEventHandler(ti_MouseLeave);
            uc.MouseMove += new MouseEventHandler(ti_MouseMove);
        }


        public void CancelBindControl(UIElement uc)
        {
            this.tip.IsOpen = false;
            uc.MouseLeave -= new MouseEventHandler(ti_MouseLeave);
            uc.MouseMove -= new MouseEventHandler(ti_MouseMove);
        }

        /// <summary>       
        /// 鼠标离开自定义控件时,隐藏提示框      
        /// </summary>       
        /// <param name="sender"></param>       
        /// <param name="e"></param>
        private void ti_MouseLeave(object sender, MouseEventArgs e)
        {
            this.tip.IsOpen = false;
        }

        /// <summary>      
        /// 鼠标在自定义控件上移动式时,提示框也跟随移动     
        /// </summary>       
        ///<param name="sender"></param>       
        /// <param name="e"></param>       
        private void ti_MouseMove(object sender, MouseEventArgs e)
        {
            this.tip.IsOpen = true;
            this.tip.HorizontalOffset = e.GetPosition(null).X - 200;
            this.tip.VerticalOffset = e.GetPosition(null).Y - 220;
        }

        #endregion


        private void tip_MouseMove(object sender, MouseEventArgs e)
        {
            this.tip.IsOpen = true;
        }

    }
}

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值