我有一个带有LinearGradientBrush的矩形。画笔的颜色之一绑定到外部资源。矩形看起来像:
<Rectangle
Width="40"
Height="40"
RadiusX="5"
RadiusY="5"
Fill="white"
Opacity="0.6">
<Rectangle.OpacityMask>
<LinearGradientBrush
x:Name="UpperShading"
StartPoint="0,0.2"
EndPoint="0,0"
MappingMode="RelativeToBoundingBox">
<GradientStop
Color="Transparent" Offset="0"/>
<GradientStop
x:Name="UpperShadingColor"
Color="{Binding
Source={StaticResource PlaybackResource},
Path=UpperLeftColor}"
Offset="1"/>
</LinearGradientBrush>
</Rectangle.OpacityMask>
</Rectangle>
绑定数据是一个简单的颜色属性:
public Color UpperLeftColor
{
get
{
return _upperleftColor;
}
set
{
_upperleftColor = value;
SetPropertyChanged("UpperLeftColor");
}
}
实际上,我想在顶部和顶部的矩形上堆叠几个矩形,当单击顶部的矩形(MouseDown)时,我想创建一个动画来更改绑定颜色的值。我试过了:
<Rectangle
Width="40"
Height="40"
RadiusX="5"
RadiusY="5"
Fill="Transparent">
<Rectangle.Triggers>
<EventTrigger RoutedEvent="MouseDown">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<ColorAnimation
Storyboard.TargetName
="{Binding Source={StaticResource PlaybackResource}}"
Storyboard.TargetProperty="UpperLeftColor"
To="{Binding Source
={StaticResource PlaybackResource}, Path=LowlightColor}"
Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Rectangle.Triggers>
</Rectangle>
但这会产生错误:(PlaybackResource是类PlaybackButtonReources的键)
“在'System.Windows.Shapes.Rectangle'的名称范围中找不到'PlaybackButtonResources'名称。”
我试图将资源添加到矩形中,但是收到了相同的错误消息。
归结为“如何为事件触发器设置绑定数据的动画?”
欢迎任何指针。
您需要将Storyboard
目标设置为GradientStop
要设置动画的目标,而不是绑定值。
尝试将您更改ColorAnimation
为以下内容:
<ColorAnimation Storyboard.TargetName="UpperShadingColor"
Storyboard.TargetProperty="Color"
To="{Binding Source={StaticResource PlaybackResource}, Path=LowlightColor}"
Duration="0:0:1"/>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句