如何通过可视状态管理器更改列表视图项模板中项目的不透明度属性?

时间:2015-05-10 13:17:34

标签: windows xaml windows-runtime windows-phone-8.1 visualstatemanager

我正在尝试listview显示由textblocksrectangles组成的项目列表。

单击listview项时,我想更改textblocks的opacity属性。

点击它时为什么会出错?

我的listview

<ListView ItemTemplate="{StaticResource tmp}" x:Name="lstviewtest1" SelectionMode="Single" ItemContainerStyle="{StaticResource ListViewItemStyle1}">
        <ItemsControl/>
</ListView>

我的资源:

<Style x:Key="ListViewItemStyle1" TargetType="ListViewItem">

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListViewItem">
                    <Border x:Name="OuterContainer" RenderTransformOrigin="0.5,0.5">
                        <Border.RenderTransform>
                            <ScaleTransform x:Name="ContentScaleTransform"/>
                        </Border.RenderTransform>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualStateGroup.Transitions>
                                    <VisualTransition From="Pressed" To="Normal">
                                        <Storyboard>
                                            <PointerUpThemeAnimation Storyboard.TargetName="TiltContainer"/>
                                        </Storyboard>
                                    </VisualTransition>
                                </VisualStateGroup.Transitions>
                                <VisualState x:Name="Normal"/>
                                <VisualState x:Name="Pressed">

                                    <Storyboard>

                                        <DoubleAnimation Storyboard.TargetName="rt1" Storyboard.TargetProperty="Opacity" To="1"/>
                                        <DoubleAnimation Storyboard.TargetName="rt2" Storyboard.TargetProperty="Opacity" To="1"/>
                                        <DoubleAnimation Storyboard.TargetName="txt1" Storyboard.TargetProperty="Opacity" To="1"/>
                                        <DoubleAnimation Storyboard.TargetName="txt2" Storyboard.TargetProperty="Opacity" To="1"/>
                                        <DoubleAnimation Storyboard.TargetName="txt3" Storyboard.TargetProperty="Opacity" To="1"/>
                                        <DoubleAnimation Storyboard.TargetName="txt4" Storyboard.TargetProperty="Opacity" To="1"/>
                                        <DoubleAnimation Storyboard.TargetName="txt5" Storyboard.TargetProperty="Opacity" To="1"/>
                                        <DoubleAnimation Storyboard.TargetName="txt6" Storyboard.TargetProperty="Opacity" To="1"/>
                                        <DoubleAnimation Storyboard.TargetName="txt7" Storyboard.TargetProperty="Opacity" To="1"/>
                                    </Storyboard>
                                </VisualState>
                                 .....
                                </Grid>
                            </Border>
                        </Grid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

<DataTemplate x:Key="tmp" >
    <Grid Width="400" Height="190">
        <Grid.RowDefinitions>
            <RowDefinition Height="55"/>
            <RowDefinition Height="145"/>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>`
            <ColumnDefinition Width="auto"/>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
       ...
        <Rectangle x:Name="rt1" Margin="17,0,27,0" Opacity="0.7" Fill="LightBlue" Grid.Column="1" Grid.Row="0" VerticalAlignment="Bottom" Height="2" />
        <Rectangle x:Name="rt2" Opacity="0" Grid.Column="0" Grid.Row="0" Grid.RowSpan="2" Width="8" Fill="LightGreen"  />
        <TextBlock x:Name="txt1" Margin="17,11,0,0" Opacity="0.7" FontSize="28" FontFamily="Candara" Grid.Column="1" Grid.Row="0" Text="Daily"   VerticalAlignment="Center" HorizontalAlignment="Left"/>
        <TextBlock x:Name="txt2" Margin="17,14.5,0,0" Opacity="0.7"  FontSize="23" FontFamily="Candara"  HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1" Text="Balance"/>
        <TextBlock x:Name="txt3" Margin="17,58,0,0" Opacity="0.7"  FontSize="23" FontFamily="Candara" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="1" Grid.Column="1" Text="Balance"/>
        <TextBlock x:Name="txt4" Margin="17,101.5,0,0" Opacity="0.7"  FontSize="23" FontFamily="Candara" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Row="2" Grid.Column="1" Text="Balance"/>
        <TextBlock x:Name="txt5" Margin="0,14.5,27,0" Opacity="0.7"  FontSize="23" FontFamily="Verdana" FontWeight="SemiBold" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Row="2" Grid.Column="1" Text="+2,372.73"/>
        <TextBlock x:Name="txt6" Margin="0,58,27,0" Opacity="0.7"  FontSize="23" FontFamily="Verdana" Foreground="#FFEC6843" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Row="2" Grid.Column="1" Text="-22,462.73"/>
        <TextBlock x:Name="txt7" Margin="0,101.5,27,0" Opacity="0.7"   FontSize="23" FontFamily="Verdana" Foreground="#FF5C9FAE" HorizontalAlignment="Right" VerticalAlignment="Top" Grid.Row="2" Grid.Column="1" Text="+2,372.73"/>
    </Grid>
</DataTemplate>

0 个答案:

没有答案