DataTemplate
으로 스타일을 지정하는 ContentControl
이 있습니다. ContentControl
외부의 애니메이션을 정의하여 DataTemplate
의 요소에 애니메이션을 적용하고 싶습니다. 내가 (대신 "MyContentControl"의) 애니메이션 템플릿에 하나 TextBox
을 대상으로 할 수 있도록하고 싶습니다 ContentControl의 DataTemplate에서 요소에 애니메이션 적용
<UserControl x:Class="StoryboardTesting.Stage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d">
<UserControl.Resources>
<DataTemplate x:Key="MyControlTemplate">
<StackPanel>
<TextBlock x:Name="TheBlock1" Text="Foo!" />
<TextBlock x:Name="TheBlock2" Text="Bar!" />
</StackPanel>
</DataTemplate>
</UserControl.Resources>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup Name="ValueStates">
<VisualState Name="ToState">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="MyContentControl"
Storyboard.TargetProperty="(UIElement.Opacity)"
Duration="0:0:1"
To="0" />
</Storyboard>
</VisualState>
<VisualState Name="FromState" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Grid>
<Canvas>
<ContentControl x:Name="MyContentControl"
ContentTemplate="{StaticResource MyControlTemplate}" />
</Canvas>
</Grid>
</UserControl>
어느 위치 나 이름이 XAML 내 시나리오의 작은, 간단한 예입니다. 나는에서 애니메이션을 시작있어
UserControl
의 코드 숨김과 같은 호출로 :
:이 ("TheBlock"와 "MyContentControl 교체") 실행하면
VisualStateManager.GoToElementState(this, "ToState", true);
, 나는 다음과 같은 얻을
InvalidOperationException : 'TheBlock1'이름을 'StoryboardTesting.Stage'의 이름 범위에서 찾을 수 없습니다.
어떤 의미가 있습니다. 속성 이름을 사용하여 두 블록을 처리하는 방법이 있습니까? 이 코드는 런타임시 생성되는 XAML이므로 코드 숨김을 피할 필요가 있습니다.
문제의 해결책을 찾으셨습니까? – Aybe