日期:2014-05-17 浏览次数:20883 次
public partial class Window1 : Window { private Storyboard myStoryBoard; public Window1() { InitializeComponent(); this.RegisterName("TestButton1", TestButton1); DoubleAnimation da = new DoubleAnimation(); da.From = 1.0; da.To = 0.0; myStoryBoard = new Storyboard(); myStoryBoard.Children.Add(da); Storyboard.SetTargetName(da, "TestButton1"); Storyboard.SetTargetProperty(da, new PropertyPath(Button.OpacityProperty)); } private void TestButton_Click(object sender, RoutedEventArgs e) { myStoryBoard.Begin(this, true); } }
------解决方案--------------------
我这么试的一个,在后台调用好使,你试着改改。
挺长时间不用,有点忘了。
txttt.Begin();
<Rectangle Name="MyRectangle" Width="100" Height="100"> <Rectangle.Fill> <SolidColorBrush x:Name="MySolidColorBrush" Color="Blue" /> </Rectangle.Fill> <Rectangle.Triggers> <EventTrigger RoutedEvent="Page.Loaded"> <BeginStoryboard> <Storyboard x:Name="txttt" RepeatBehavior="Forever" AutoReverse="True"> <DoubleAnimation Storyboard.TargetName="MyRectangle" Storyboard.TargetProperty="Width" From="100" To="200" Duration="0:0:1" /> <ColorAnimation Storyboard.TargetName="MySolidColorBrush" Storyboard.TargetProperty="Color" From="Blue" To="Red" Duration="0:0:1" /> </Storyboard> </BeginStoryboard> </EventTrigger> </Rectangle.Triggers> </Rectangle>