这是我的示例代码,用于在页面加载期间为进度栏设置动画。
我的问题是,单击按钮后如何启动进度栏?
<ProgressBar Height="50" Minimum="0" Maximum="100" Value="0"
RenderTransformOrigin="0.5,0.5"
Margin="-113,0" Background="Transparent"
BorderThickness="0" Foreground="DarkCyan">
<ProgressBar.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</ProgressBar.RenderTransform>
<ProgressBar.Triggers>
<EventTrigger RoutedEvent="FrameworkElement.Loaded">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Value"
From="0" To="{Binding Bar1}"
Duration="{Binding Duration1}"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ProgressBar.Triggers>
</ProgressBar>
最佳答案
脚步:
给<ProgressBar />
命名,然后删除Triggers
。
<ProgressBar x:Name="MyProgressBar" Height="50" Minimum="0" Maximum="100" Value="0"
RenderTransformOrigin="0.5,0.5"
Margin="-113,0" Background="Transparent"
BorderThickness="0" Foreground="DarkCyan">
<ProgressBar.RenderTransform>
<TransformGroup>
<ScaleTransform/>
<SkewTransform/>
<RotateTransform Angle="-90"/>
<TranslateTransform/>
</TransformGroup>
</ProgressBar.RenderTransform>
</ProgressBar>
添加您的
<Button />
,其Triggers
,TargetName
等于<ProgressBar />
名称。 <Button Content="Press to trigger">
<Button.Triggers>
<EventTrigger RoutedEvent="Button.Click">
<EventTrigger.Actions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetProperty="Value" Storyboard.TargetName="MyProgressBar"
From="0" To="100"
Duration="0:0:1"/>
</Storyboard>
</BeginStoryboard>
</EventTrigger.Actions>
</EventTrigger>
</Button.Triggers>
</Button>
结果: