VisualStateManager
요소는 컨트롤 템플릿의 루트의 자식으로 위치해야합니다 : 여기
<ControlTemplate x:Key="AnimatedImage" TargetType="{x:Type Image}">
<Grid>
<Image Name="image"
Source="{TemplateBinding Filename}"
Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="AnimationLocations">
<!-- When the image is first loaded move it to the center of the InkCanvas -->
<VisualState Name="AnimateToCenterScreen">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="image"
Storyboard.TargetProperty="(Image.RenderTransform).(TranslateTransform.X)"
From="{TemplateBinding From}"
To="{TemplateBinding To}"
Duration="{TemplateBinding Duration}" />
</Storyboard>
</VisualState>
<!-- Animate the image to an off screen position to effectively hide it. -->
<VisualState Name="AnimateToOffScreen">
<!-- To be filled in later. -->
</VisualState>
<!-- Animate the image back to the original on screen position. -->
<VisualState Name="AnimateToOnScreen">
<!-- To be filled in later. -->
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Image>
</Grid>
</ControlTemplate>
메인 그리드에 대한 XAML입니다.
<ControlTemplate x:Key="AnimatedImage" TargetType="{x:Type Image}">
<Grid>
<VisualStateManager.VisualStateGroups>
...
</VisualStateManager.VisualStateGroups>
<Image Name="image" ... />
</Grid>
</ControlTemplate>
(참조
here를 들어 당신이 그 재미있는 이야기를 찾을 수 있습니다 MSDN의 페이지입니다.)
이렇게 빨리 응답 해 주셔서 감사합니다. – user2986938
너무 빨리 응답 해 주셔서 감사합니다. 제안 된 변경 사항을 적용한 후에도 Image 컨트롤에서 AnimatedImage를 템플릿으로 사용할 수 없습니다. Image 컨트롤에는 Template 속성이 없습니다. 너무 많은 문제가 아니라면 xtype Image가있는 controltemplate의 예와 이미지 컨트롤에서 해당 템플릿을 참조하는 방법을 요청할 수 있습니까? – user2986938
@ user2986938 아 죄송합니다. 애니메이션 속성에 TemplateBinding을 사용하려고했는지 알지 못했습니다. 'To','From' 및'Duration' 속성은 종속 속성이 아니므로 바인드 할 수 없습니다. 다른 방법을 찾아야합니다. – McGarnagle