如何在 Blend 中将径向渐变的 X/Y 坐标数据绑定到鼠标光标的 X/Y 坐标?

How do I data bind the X/Y coordinates of a radial gradient to the X/Y coordinates of the mouse cursor in Blend?

我正在学习如何在 VS Blend 中创建 Windows Vista/7 风格的玻璃按钮的 this 教程(我使用的是 VS 2013 社区版)。当谈到按钮闪耀时,我想重新创建 Windows 7 如何处理任务栏上的按钮 - 例如,当鼠标悬停在按钮上时,构成闪耀本身的径向渐变总是以光标为中心。

我的猜测是我想将渐变的位置(x 和 y)绑定到光标坐标。

如何在 Blend 中将径向渐变的坐标数据绑定到鼠标光标的 x/y 坐标?

一种方法是向视图添加依赖项 属性,并将其挂接到 MouseMove 事件。

依赖项属性:

    public static readonly DependencyProperty MousePointProperty = DependencyProperty.Register(
        "MousePoint",
        typeof (Point),
        typeof (MyWindow),
        new FrameworkPropertyMetadata(new Point());

    public Point MousePoint
    {
        get { return (Point)GetValue(MousePointProperty ); }
        set { SetValue(MousePointProperty , value); }
    }

然后在 MouseMove 处理程序中,更新此点。在 XAML 中(这是在一个矩形上,您的控件应该类似):

<Rectangle>
    <Rectangle.Fill>
        <RadialGradientBrush GradientOrigin="{Binding MousePoint}"/>
    </Rectangle.Fill>
</Rectangle>