私は以下の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
を使用してみましたが、それはただ単にTextBlock
それの内部全体ContentPresenter
の不透明度を設定していません。
<DoubleAnimation Storyboard.TargetName="ContentPresenter" Storyboard.TargetProperty="(TextBlock.Opacity)" Duration="0" To="1" />
DataTemplateのグリッドコントロール内でストーリーボードを設定しようとしましたか? – AVK
私は、Grid.Resource内にストーリーボードを置くとき、私はそれを開始するためにコードビハインドからアクセスできません。私はPage.Resourceに私は "インストールされていないコンポーネントが検出された" COMExceptionを取得します。どちらが始まるのかわからないので推測します。 –