【问题标题】:Can't reach Storyboard object in C#无法在 C# 中访问 Storyboard 对象
【发布时间】:2012-07-07 06:02:02
【问题描述】:

所以我有这个 XAML:

<ListBox Height="626" HorizontalAlignment="Left" Margin="6,6,0,0" Name="ItemList" VerticalAlignment="Top" Width="444">
    <ListBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Vertical">
                <Grid Height="50">
                    <Grid.Resources>
                        <Storyboard x:Name="ItemCountBGImageShow">
                            <DoubleAnimation Storyboard.TargetName="ItemCountBGImage"
                                Storyboard.TargetProperty="Opacity"
                                From="0" To="100" Duration="0:0:0.3" />
                        </Storyboard>
                    </Grid.Resources>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="31" />
                        <ColumnDefinition Width="300" />
                        <ColumnDefinition Width="100" />
                    </Grid.ColumnDefinitions>

                    <Image Opacity="0" Grid.ColumnSpan="1" Name="ItemCountBGImage" Width="31" Height="31" Source="/CafeKonto.wp7;component/Images/table_quantity.png" />
                    <TextBlock Grid.ColumnSpan="2"  FontSize="25" Name="ItemName" Foreground="White" Tap="ItemName_Tap" Text="{Binding ItemName}" Margin="35,0,0,0" />
                    <TextBlock Grid.ColumnSpan="3" TextAlignment="Right" FontSize="25" Name="ItemPrice" Foreground="White" Text="{Binding ItemPriceFormated}" />
                </Grid>
            </StackPanel>
        </DataTemplate>
    </ListBox.ItemTemplate>
</ListBox>

我的问题是,我无法从 C# 启动动画。 ItemCountBGImageShow 在后面的代码中是不可见的。我在这里做错了什么?

【问题讨论】:

    标签: c# .net windows-phone-7 xaml storyboard


    【解决方案1】:

    您不能像这样访问元素资源字典中的项目。

    给网格命名,然后使用它的 Resources 属性访问它。

    例子:

    XAML:

    <Grid Name="Grid1" Height="50"> 
    

    代码:

    Storyboard ItemCountBGImageShow = (Storyboard)Grid1.Resources["ItemCountBGImageShow"];
    

    【讨论】:

    • 这也不起作用。我认为这是因为情节提要位于列表框中。不知何故,我需要获取正确的故事板实例并启动它。
    猜你喜欢
    • 2012-11-04
    • 1970-01-01
    • 2017-05-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多