Reputation: 364
So I have this 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>
My problem is, I cannot start the animation from C#. ItemCountBGImageShow is not visible in the code behind. What am I doing wrong here?
Upvotes: 0
Views: 219
Reputation: 30830
You cannot access an item in an element's resource dictionary like that.
Give grid a name and then access it using it's Resources property.
Example:
XAML:
<Grid Name="Grid1" Height="50">
Code:
Storyboard ItemCountBGImageShow = (Storyboard)Grid1.Resources["ItemCountBGImageShow"];
Upvotes: 1