2

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

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

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

4

1 回答 1

3

一种方法是向视图添加依赖属性,并将其与 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>
于 2015-04-02T08:29:29.657 回答