tags:

views:

103

answers:

0

I'd like to aligns the tooltip's lower edge with the upper edge of the PlacementTarget, and align the tooltip's left edge with mouse position,

I have two screen, both 1920 x 1080, when I ran the program in the main screen, the tooltip jump to the second screen when mouse's x position larger than 770,

if I ran it in the second screen, it works great,

Is it a bug?

anyway to workaround this?

namespace WpfApplication1
{
    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>
    public partial class Window1 : Window
    {
        #region OffsetX

        /// <summary>
        /// OffsetX Dependency Property
        /// </summary>
        public static readonly DependencyProperty OffsetXProperty =
            DependencyProperty.Register("OffsetX", typeof(double), typeof(Window1),
                new FrameworkPropertyMetadata((double)0));

        /// <summary>
        /// Gets or sets the OffsetX property.  This dependency property 
        /// indicates ....
        /// </summary>
        public double OffsetX
        {
            get { return (double)GetValue(OffsetXProperty); }
            set { SetValue(OffsetXProperty, value); }
        }

        #endregion




        public Window1()
        {
            InitializeComponent();
            DataContext = this;
        }

        private void button1_MouseMove(object sender, MouseEventArgs e)
        {
            OffsetX = e.GetPosition(button1).X;
            Title = OffsetX.ToString();
        }
    }
}


<Window x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window1" Height="300" Width="300" WindowState="Maximized">
    <Grid>
        <Button Height="23" Name="button1" 
                Content="Test"
                ToolTipService.ShowDuration="9999999"
                VerticalAlignment="Bottom" MouseMove="button1_MouseMove">
            <Button.ToolTip>
                <ToolTip
                    Placement="Top"
                    HorizontalOffset="{Binding Path=OffsetX}"
                    >
                    <Rectangle Width="100" Height="100" Fill="Yellow"/>
                </ToolTip>
            </Button.ToolTip>
        </Button>
    </Grid>
</Window>