MVVM 응용 프로그램에서 작업 중이며 ProgressBar에 속성이 변경 될 때 새 값으로 부드럽게 움직 이도록하고 싶습니다. C#을 사용하여이 질문에 대한 몇 가지 답변을 보았습니다. 그러나 템플릿 내부에서이 작업을 수행하는 것을 선호합니다. 내가 가지고있는 문제는 이벤트와 스토리 보드를 올바르게 설정하고 타겟팅하는 것입니다. 여기에 내가 현재 가지고있는 것입니다 :WPF 템플릿에서 부드럽게 애니메이션 된 ProgressBar
는진행은
여기에서 트리거 코드를 갔던 스타일 - (바로 트리거)
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="RangeBase.ValueChanged">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="???????"
Storyboard.TargetProperty="Value"
To="???????" Duration="0:0:5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
을 바 - : http://msdn.microsoft.com/en-us/library/system.windows.controls.progressbar(v=vs.110).aspx.
어떻게이 템플릿을 사용하는 모든 컨트롤에 적용되도록 TargetName을 템플릿 자체로 설정합니까? 수신 가치에 "받는 사람"을 어떻게 설정합니까? "Binding"값을 가져 오는 방법이있는 것처럼 보이지만 Valuebar 및 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" BorderThickness="1" CornerRadius="10,0,10,0" BorderBrush="Black"></Border>
<Border x:Name="BordeCabeceraSombra" BorderThickness="2" CornerRadius="10,0,10,0" BorderBrush="DarkGray" Opacity=".2" Margin="1,1,1,0"></Border>
<Label x:Name="Progress" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" FontWeight="Bold" Foreground="White" Opacity=".7" Content="{Binding Path=Value, RelativeSource={RelativeSource TemplatedParent}}"></Label>
</Grid>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="RangeBase.ValueChanged">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="???????"
Storyboard.TargetProperty="Value"
From="???????" To="???????" Duration="0:0:5" />
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<Trigger Property="IsIndeterminate" Value="True">
<Setter Property="Visibility" TargetName="Progress" Value="Hidden"></Setter>
<Setter Property="Background" TargetName="PART_Indicator">
<Setter.Value>
<MultiBinding>
<MultiBinding.Converter>
<wintheme:ProgressBarHighlightConverter/>
</MultiBinding.Converter>
<Binding Source="{StaticResource GlowFXProgressAnimated}"/>
<Binding Path="ActualWidth" ElementName="BaseRectangle"/>
<Binding Path="ActualHeight" ElementName="BaseRectangle"/>
</MultiBinding>
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Opacity" Value=".5"></Setter>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
어떤 도움을 주시면 감사하겠습니다!
난 당신이 XAML에서 스토리 보드를 사용하여이 작업을 수행 할 수 있습니다 생각하지 않습니다,하지만 당신은 롤 수 붙은 행동으로 행동. 애니메이션은 C# 코드에서 계속 적용되지만 코드는 재사용 가능한 동작으로 캡슐화되며 사용자의 스타일에 따라 동작을 활성화 할 수 있습니다. –