C# 在WPF中使用情节提要设置网格背景颜色的动画
我是WPF故事板的新手。我想设置网格背景颜色的动画。我得到了这个错误: System.InvalidOperationException:'无法解析所有属性 属性路径“Background.Color”中的引用。核实 适用对象支持属性。” 我的XAML代码:C# 在WPF中使用情节提要设置网格背景颜色的动画,c#,.net,wpf,xaml,storyboard,C#,.net,Wpf,Xaml,Storyboard,我是WPF故事板的新手。我想设置网格背景颜色的动画。我得到了这个错误: System.InvalidOperationException:'无法解析所有属性 属性路径“Background.Color”中的引用。核实 适用对象支持属性。” 我的XAML代码: <Grid x:Name="alert_grid"> <Grid.Resources> <Storyboard x:Key="flashing_storyboard" S
<Grid x:Name="alert_grid">
<Grid.Resources>
<Storyboard x:Key="flashing_storyboard" Storyboard.TargetName="alert_grid">
<ColorAnimation
Storyboard.TargetProperty="Background.Color"
From="Black" To="Orange" Duration="0:0:2"
AutoReverse="True" RepeatBehavior="Forever" />
</Storyboard>
</Grid.Resources>
</Grid>
你知道如何设置背景色动画吗?请试试这个
<Grid Name="alert_grid" Height="75" HorizontalAlignment="Left" Margin="27,12,0,0" VerticalAlignment="Top" Width="160" Background="LightGray">
<Grid.Triggers>
<EventTrigger RoutedEvent="Button.MouseLeave">
<BeginStoryboard>
<Storyboard x:Name ="flashing_storyboard" Storyboard.Target="{Binding ElementName=alert_grid}">
<ColorAnimation To="Orange" Storyboard.TargetProperty="(Grid.Background).(SolidColorBrush.Color)" From="Black"
AutoReverse="True" RepeatBehavior="Forever" FillBehavior="Stop" Duration="0:0:2"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
</Grid>
请试试这个
<Grid Name="alert_grid" Height="75" HorizontalAlignment="Left" Margin="27,12,0,0" VerticalAlignment="Top" Width="160" Background="LightGray">
<Grid.Triggers>
<EventTrigger RoutedEvent="Button.MouseLeave">
<BeginStoryboard>
<Storyboard x:Name ="flashing_storyboard" Storyboard.Target="{Binding ElementName=alert_grid}">
<ColorAnimation To="Orange" Storyboard.TargetProperty="(Grid.Background).(SolidColorBrush.Color)" From="Black"
AutoReverse="True" RepeatBehavior="Forever" FillBehavior="Stop" Duration="0:0:2"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</Grid.Triggers>
</Grid>
背景是画笔而不是颜色。不管怎么说,既然已经有了代码,就可以将solidcolorbrush从控件的背景属性中取出,并在代码中进行彩色动画。没有任何故事板。背景是画笔而不是颜色。不管怎么说,既然已经有了代码,就可以将solidcolorbrush从控件的背景属性中取出,并在代码中进行彩色动画。没有任何故事板。
Storyboard sb = alert_grid.FindName("flashing_storyboard") as Storyboard;
if (sb != null)
{
sb.Begin();
}