Xaml에 있는 Storyboard를 새로생성된 오브젝트에 적용하기
일단 스토리보드는 타겟이 있어야 한다 대부분 디자이너나 블랜드에서 만들면 타겟을
Storyboard.TargetName="xDetailItem"
이런코드가 삽입된다
일단 xaml에서 TargetName을 다 제거한다.. 그리고 이 타겟을 Behind에서 추가해준다.
일단 아래와 같이 제거
<Storyboard x:Key="CalculatorOpen">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)">
<EasingDoubleKeyFrame KeyTime="0" Value="0" />
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleX)">
<EasingDoubleKeyFrame KeyTime="0" Value="0" />
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1" />
</DoubleAnimationUsingKeyFrames>
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(ScaleTransform.ScaleY)">
<EasingDoubleKeyFrame KeyTime="0" Value="0" />
<EasingDoubleKeyFrame KeyTime="0:0:0.3" Value="1" />
</DoubleAnimationUsingKeyFrames>
</Storyboard>
자 이제 code behind에서
ScatterViewItem svi = new ScatterViewItem()
{
Center = (e.Source as DragAndDropScatterViewItem).Center,
Content = CalUc,
Orientation = 0,
Width = 263,
Height = 311,
RenderTransformOrigin = new Point(0.5, 0.5),
CanScale = false,
};
TransformGroup transGroup = new TransformGroup();
transGroup.Children.Add(new ScaleTransform());
transGroup.Children.Add(new TranslateTransform());
transGroup.Children.Add(new RotateTransform());
transGroup.Children.Add(new SkewTransform());
svi.RenderTransform = transGroup;
xScatterView.Items.Add(svi);
이런식으로 오브젝트를 하나 만들었다.
xaml에 Transform을 이용하기 떄문에 오브젝트에서도 이렇게 만들어줘야 된다.
자 간단하게 타겟을 지정해보자.
Storyboard sb = this.Resources["CalculatorOpen"] as Storyboard;
sb.Begin(svi);
아... 간단하다. begin(오브젝트)만 붙이면 된다.