다음 GridView
을 사용하고 있으며 내부에 3 개의 요소가있는 ItemTemplate
이 있습니다.Visualstate 애니메이션을위한 ContentPresenter 하위에 액세스
이제 GridViewItem에서 PointerOver
의 MyTextBlock 불투명도에 애니메이션을 적용하려고합니다.
<GridView x:Name="MyList" ItemContainerStyle="{StaticResource GridViewItemContainerStyle}" ItemsSource="{Binding MyList}">
<GridView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="200" />
<RowDefinition Height="3" />
<RowDefinition Height="80" />
</Grid.RowDefinitions>
<Image Grid.Row="0" Source="{Binding Url}" />
<ProgressBar Grid.Row="1" IsIndeterminate="True" />
<TextBlock Name="MyTextBlock" Opacity="0" Text="Test" />
</Grid>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
ItemContainerStyle
은 이와 유사합니다. 문제는, 내가 ContentPresenter
안에 있기 때문에 여기에서 Storyboard.TargetName="MyTextBlock"
으로 MyTextBlock
에 액세스 할 수 없습니다. ContentPresenter
안에있는 요소의 visualstate 애니메이션을 어떻게 만들 수 있습니까?
<Style TargetType="GridViewItem" x:Key="GridViewItemContainerStyle">
...
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GridViewItem">
<Grid x:Name="ContentBorder" Control.IsTemplateFocusTarget="True" RenderTransformOrigin="0.5,0.5">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="CommonStates">
<VisualState x:Name="Normal">
<Storyboard>
<PointerUpThemeAnimation Storyboard.TargetName="ContentPresenter" />
</Storyboard>
</VisualState>
<VisualState x:Name="PointerOver">
<Storyboard>
<DoubleAnimation Storyboard.TargetName="BorderRectangle" Storyboard.TargetProperty="Opacity" Duration="0" To="1" />
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<Rectangle x:Name="BorderRectangle" Fill="{ThemeResource SystemControlHighlightListAccentLowBrush}" Opacity="0" />
<ContentPresenter x:Name="ContentPresenter" ContentTransitions="{TemplateBinding ContentTransitions}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="{TemplateBinding Padding}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
편집 : 내가 다음 TargetProperty
을 사용했지만, 단지 그것의 내부 전체 ContentPresenter
뿐 아니라 TextBlock
의 불투명도를 설정합니다.
<DoubleAnimation Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="(TextBlock.Opacity)" Duration="0" To="1" />
DataTemplate의 Grid Control 안에 스토리 보드를 설정해 보았습니까? – AVK
내가 스토리 보드를 Grid.Resource에 넣었을 때 코드 비하인드에서 스토리 보드에 액세스 할 수 없습니다. Page.Resource에 넣을 때 "No installed components were detected"라는 COMException이 발생합니다. 어느 쪽이 시작할 지 모르기 때문에 나는 추측한다. –