نمایش نتایج 1 تا 2 از 2

نام تاپیک: آیا میشه زمان KeyTime ها رو در storyboard تغییر داد ؟

  1. #1
    کاربر دائمی آواتار mdssoft
    تاریخ عضویت
    خرداد 1386
    محل زندگی
    تهران / ساری
    پست
    392

    آیا میشه زمان KeyTime ها رو در storyboard تغییر داد ؟

    با سلام.

    من در پروژم ، Storyboard زیر رو دارم :

    <Storyboard x:Key="Storyboard1">
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="top">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.1"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="topLeft">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.1"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="middle">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.1"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="bottomLeft">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.1"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="bottom">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.1"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="topRight">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.995"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="bottomRight">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.995"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="topBlur">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.1"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="topLeftBlur">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.1"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="middleBlur">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.1"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="bottomLeftBlur">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.1"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="bottomBlur">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="0.1"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="topRightBlur">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="bottomRightBlur">
    <EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1"/>
    </DoubleAnimationUsingKeyFrames>
    </Storyboard>


    چطور می تونم KeyTime های DoubleAnimationUsingKeyFrames رو از طریق کد C#‎ تغییر بدم ؟

    ممنون.

  2. #2

    نقل قول: آیا میشه زمان KeyTime ها رو در storyboard تغییر داد ؟

    سلام
    من از یک روش استفاده میکنم که با یک مثال این روش رو توضیح میدم
    فرض کنیم StoryBoard ما این باشه
    <Storyboard x:Key="OnClick1"  >
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Width )" Storyboard.TargetName="Window">
    <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="900"/>
    </DoubleAnimationUsingKeyFrames>
    </Storyboard>


    حالا با کد زیر زمان رو نصف میکنم
     System.Windows.Media.Animation.Storyboard sb = FindResource("OnClick1") as System.Windows.Media.Animation.Storyboard;
    sb.SpeedRatio = 2;


    کد زیر اونو دوبرابر میکنه
     System.Windows.Media.Animation.Storyboard sb = FindResource("OnClick1") as System.Windows.Media.Animation.Storyboard;
    sb.SpeedRatio = 0.5;


    راه دوم
    var sb = FindResource("OnClick1") as System.Windows.Media.Animation.Storyboard;
    var ani = sb.Children[0] as System.Windows.Media.Animation.DoubleAnimationUsin gKeyFrames;
    var keyFrames = ani.KeyFrames[0];

    keyFrames.KeyTime = System.Windows.Media.Animation.KeyTime.FromTimeSpa n(new TimeSpan(0, 0, 0, 20));


    نکته ممکنه تعداد DoubleAnimationUsingKeyFrames بیش از یک مورد باشه ( مثل مثال خودتون)
    مثلا
    <Storyboard x:Key="OnClick1"  >
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransf orm).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)" Storyboard.TargetName="button1">
    <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="1.279"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransf orm).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)" Storyboard.TargetName="button1">
    <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="1.514"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransf orm).(TransformGroup.Children)[3].(TranslateTransform.X)" Storyboard.TargetName="button1">
    <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="12"/>
    </DoubleAnimationUsingKeyFrames>
    <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransf orm).(TransformGroup.Children)[3].(TranslateTransform.Y)" Storyboard.TargetName="button1">
    <EasingDoubleKeyFrame KeyTime="0:0:0.6" Value="9"/>
    </DoubleAnimationUsingKeyFrames>
    </Storyboard>


    کدش به این شکل میشه
             var sb = FindResource("OnClick1") as System.Windows.Media.Animation.Storyboard;

    var ani = sb.Children[0] as System.Windows.Media.Animation.DoubleAnimationUsin gKeyFrames;
    var keyFrames = ani.KeyFrames[0];
    keyFrames.KeyTime = System.Windows.Media.Animation.KeyTime.FromTimeSpa n(new TimeSpan(0, 0, 0, 20));

    ani = sb.Children[1] as System.Windows.Media.Animation.DoubleAnimationUsin gKeyFrames;
    keyFrames = ani.KeyFrames[0];
    keyFrames.KeyTime = System.Windows.Media.Animation.KeyTime.FromTimeSpa n(new TimeSpan(0, 0, 0, 20));

    ani = sb.Children[2] as System.Windows.Media.Animation.DoubleAnimationUsin gKeyFrames;
    keyFrames = ani.KeyFrames[0];
    keyFrames.KeyTime = System.Windows.Media.Animation.KeyTime.FromTimeSpa n(new TimeSpan(0, 0, 0, 20));

    ani = sb.Children[3] as System.Windows.Media.Animation.DoubleAnimationUsin gKeyFrames;
    keyFrames = ani.KeyFrames[0];
    keyFrames.KeyTime = System.Windows.Media.Animation.KeyTime.FromTimeSpa n(new TimeSpan(0, 0, 0, 20));


    یا به شکل خلاصه
      var sb = FindResource("OnClick1") as System.Windows.Media.Animation.Storyboard;
    foreach (var ani in sb.Children)
    {
    var keyFrames = (ani as System.Windows.Media.Animation.DoubleAnimationUsin gKeyFrames).KeyFrames[0];
    keyFrames.KeyTime = System.Windows.Media.Animation.KeyTime.FromTimeSpa n(new TimeSpan(0, 0, 0, 20));
    }


    امیدوارم منظور رو رسونده باشم
    البته من پیشنهاد میکنم در مواقعی که نیاز دارید انیمیشن متغییر داشته باشید کلا اونو در code Behind بنویسید
    در لینک زیر یک مثال از این مسئله وجود داره
    https://barnamenevis.org/showthread.p...86%D8%B1%DB%8C
    آخرین ویرایش به وسیله مهدی فرزاد : پنج شنبه 05 خرداد 1390 در 00:21 صبح

برچسب های این تاپیک

قوانین ایجاد تاپیک در تالار

  • شما نمی توانید تاپیک جدید ایجاد کنید
  • شما نمی توانید به تاپیک ها پاسخ دهید
  • شما نمی توانید ضمیمه ارسال کنید
  • شما نمی توانید پاسخ هایتان را ویرایش کنید
  •