I’m trying to create a simple image rotator control where a user can click an arrow and an image will slide to another one. I’m doing this with a stackpanel of images inside of a scrollviewer.
n silverlight, the following code works as expected:
<Grid x:Name="RootLayout" Margin="200" Width="480">
<Grid.RowDefinitions>
<RowDefinition Height="50" />
<RowDefinition Height="50" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="50" />
<ColumnDefinition Width="50" />
</Grid.ColumnDefinitions>
<ScrollViewer Grid.Row="0" Grid.Column="0" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden">
<StackPanel Orientation="Horizontal">
<StackPanel.RenderTransform>
<TranslateTransform x:Name="tt" />
</StackPanel.RenderTransform>
<StackPanel.Resources>
<Storyboard x:Name="sb">
<DoubleAnimation
Storyboard.TargetName="tt"
Storyboard.TargetProperty="X"
From="0"
To="-50"
Duration="0:0:0.25" />
</Storyboard>
</StackPanel.Resources>
<Rectangle Width="50" Height="50" Fill="Blue" />
<Rectangle Width="50" Height="50" Fill="Green" />
</StackPanel>
</Scrol开发者_JAVA技巧lViewer>
<Button Content="Push" Click="test" Grid.Row="1" Grid.Column="1" />
</Grid>
The "Push" button simply begins the storyboard.
Now, when I use this same code in a wp7 page, I get a runtime error on the Begin method of the storyboard saying that the targetname could not be resolved. Interestingly enough, if I remove the ScrollViewer wrapped around the StackPanel completely, the page runs just fine. Why would it fail on wp7 when the stackpanel is contained inside the scrollviewer? (Note that the root level of the phone page is phone:PhoneApplicationPage)
Thanks!
Can't answer why there is a difference, but generally when I have been writing storyboards on WP7 I reference the transform I want like this.
Storyboard.TargetName="myStackPanel" Storyboard.TargetProperty="(UIElement.RenderTransform).(TranslateTransform.X)
Perhaps there is a difference in the traveral algorithms.
精彩评论