我正在开发一个MVVM应用程序,我希望有一个ProgressBar,当该属性发生变化时,它可以平滑地动画到它的新值.我已经使用c#看到了这个问题的几个答案,但我更喜欢在模板中完成所有操作.我遇到的问题是正确设置和定位事件和故事板.这是我目前的情况:
进度条 -
风格 - (只是触发器)
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="RangeBase.ValueChanged">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="???????"
Storyboard.TargetProperty="Value"
To="???????" Duration="0:0:5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
Run Code Online (Sandbox Code Playgroud)
我从这里获取了触发器代码:http://msdn.microsoft.com/en-us/library/system.windows.controls.progressbar(v = vs.110).aspx.
如何将TargetName设置为模板本身,以便它适用于使用此模板的所有控件?如何为传入值设置"收件人"?似乎有一种方法可以获取"Binding"值,但我有Value和Max都绑定在progressbar元素上.怎么会知道怎么用?
以下是整个模板供参考:
<Style x:Key="ProgressStyle" TargetType="{x:Type ProgressBar}">
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="SnapsToDevicePixels" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ProgressBar}">
<Grid MinHeight="14" MinWidth="20">
<Border x:Name="BaseRectangle" Background="{StaticResource BaseColor}" CornerRadius="10,0,10,0"></Border>
<Border x:Name="GlassRectangle" CornerRadius="10,0,10,0" Background="{StaticResource GlassFX}" Panel.ZIndex="10"></Border>
<Border x:Name="animation" CornerRadius="10,0,10,0" Opacity=".7" Background="{Binding Path=Foreground, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Left"></Border>
<Border x:Name="PART_Indicator" CornerRadius="10,0,10,0" Background="{Binding Path=Foreground, RelativeSource={RelativeSource TemplatedParent}}" HorizontalAlignment="Left"></Border>
<Border x:Name="PART_Track" …Run Code Online (Sandbox Code Playgroud)