Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
202 views
in Technique[技术] by (71.8m points)

c# - Storyboard.SetTarget vs Storyboard.SetTargetName

Why does Storyboard.SetTargetName works but Storyboard.SetTarget does not? Here xaml -

    <Grid Grid.Row="0" ClipToBounds="True">
        <X:SmartContentControl  x:Name="smartContent"  Content="{Binding Path=MainContent}" ContentChanging="smartContent_ContentChanging">
            <X:SmartContentControl.RenderTransform>
                <TranslateTransform x:Name="translateTransformNew" X="0" Y="0"/>
            </X:SmartContentControl.RenderTransform>
        </X:SmartContentControl>
        <ContentControl Content="{Binding ElementName=smartContent, Path=LastImage}">
            <ContentControl.RenderTransform>
                <TranslateTransform x:Name="translateTransformLast" X="0" Y="0"/>
            </ContentControl.RenderTransform>
        </ContentControl>
    </Grid>

Here C#

private void smartContent_ContentChanging(object sender, RoutedEventArgs e)
{
    Storyboard storyBoard = new Storyboard();
    DoubleAnimation doubleAnimation1 = new DoubleAnimation(0.0, -smartContent.RenderSize.Width, new Duration(new TimeSpan(0, 0, 0, 0, 500)));
    DoubleAnimation doubleAnimation2 = new DoubleAnimation(smartContent.RenderSize.Width, 0.0, new Duration(new TimeSpan(0, 0, 0, 0, 500)));

    doubleAnimation1.AccelerationRatio = 0.5;
    doubleAnimation2.DecelerationRatio = 0.5;
    storyBoard.Children.Add(doubleAnimation1);
    storyBoard.Children.Add(doubleAnimation2);
    Storyboard.SetTarget(doubleAnimation1, this.translateTransformLast); //--- this does not work
    //Storyboard.SetTargetName(doubleAnimation1, "translateTransformLast"); -- this works
    Storyboard.SetTargetProperty(doubleAnimation1, new PropertyPath(TranslateTransform.XProperty));
    Storyboard.SetTarget(doubleAnimation2, this.translateTransformNew);//--- this does not work
    //Storyboard.SetTargetName(doubleAnimation2, "translateTransformNew"); -- this works
    Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath(TranslateTransform.XProperty));
    if (smartContent.LastImage != null)
        storyBoard.Begin();
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I found answer here! Why don't these animations work when I'm using a storyboard?

Storyboard cant animate TranslateTransform, since it is not UIElement. This is how i do it now! :)

  Storyboard.SetTarget(doubleAnimation1, this.lastImage);
    Storyboard.SetTargetProperty(doubleAnimation1, new PropertyPath("RenderTransform.(TranslateTransform.X)"));

    Storyboard.SetTarget(doubleAnimation2, this.smartContent);
    Storyboard.SetTargetProperty(doubleAnimation2, new PropertyPath("RenderTransform.(TranslateTransform.X)"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...