{"id":4087,"date":"2013-02-21T09:30:28","date_gmt":"2013-02-21T00:30:28","guid":{"rendered":"http:\/\/www.moonmile.net\/blog\/archives\/4087"},"modified":"2013-02-20T12:41:05","modified_gmt":"2013-02-20T03:41:05","slug":"winrt-storyboard-clone-%e3%82%92%e4%bd%9c%e3%82%8b","status":"publish","type":"post","link":"http:\/\/www.moonmile.net\/blog\/archives\/4087","title":{"rendered":"[WinRT] Storyboard.Clone \u3092\u4f5c\u308b"},"content":{"rendered":"<p>\n\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u306e\u5834\u5408\u306f\u3001\n<\/p>\n<ol>\n<li>Storyboard \u306e\u5834\u5408\u306f\u3001Blend \u3067\u3061\u307e\u3061\u307e\u7de8\u96c6\u3057\u3066\u52d5\u4f5c\u78ba\u8a8d<\/li>\n<li>\u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30fc\u30c9\u306b\u7d44\u307f\u8fbc\u3093\u3067\u3001\u52d5\u4f5c\u78ba\u8a8d<\/li>\n<li>\u3082\u3046\u4e00\u5ea6\u3001Blend \u306b\u623b\u3063\u3066\u4fee\u6b63\u3002<\/li>\n<li>\u307e\u305f\u307e\u305f\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30fc\u30c9\u306b\u7d44\u307f\u8fbc\u3093\u3067\u3001\u52d5\u4f5c\u78ba\u8a8d<\/li>\n<\/ol>\n<p>\n\u3063\u3066\u3044\u3046\u7e70\u308a\u8fd4\u3057\u306b\u306a\u308b\u306e\u3067\u3001Blend \u3067\u30c7\u30b6\u30a4\u30f3\u3001Visual Studio \u3067\u30d3\u30eb\u30c9\u3057\u3066\u304b\u3089\u30b7\u30df\u30e5\u30ec\u30fc\u30bf\u30fc\u3067\u78ba\u8a8d\u3001\u3063\u3066\u306e\u304c\u5b9a\u756a&#8230;\u306b\u306a\u308b\u3068\u601d\u3046\u306e\u3067\u3059\u304c\u3001\u3069\u3046\u306a\u3093\u3067\u3057\u3087\u3046\uff1f\u305d\u3093\u306a\u306b\u8907\u96d1\u306a Storyboard \u306f\u4f5c\u3089\u306a\u3044\u306e\u304b\u306a\uff1f\n<\/p>\n<p>\n\u25a0Storyboard.Clone \u3092\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9\u3067\u4f5c\u308b\n<\/p>\n<p>\n\u30ea\u30d5\u30ec\u30af\u30b7\u30e7\u30f3\u3068\u304b\u4f7f\u3063\u3066\u6b63\u78ba\u306b\u66f8\u3053\u3046\u3068\u3082\u601d\u3063\u305f\u306e\u3067\u3059\u304c\u3001\u3055\u307b\u3069\u8907\u96d1\u306a\u69cb\u9020\u3067\u3082\u306a\u3044\u3057\u3001\u5165\u308c\u5b50\u306b\u306a\u308b\u30af\u30e9\u30b9\u306f\u6c7a\u307e\u3063\u3066\u3044\u308b\u306e\u3067\u3060\u3089\u3060\u3089\u3068150\u884c\u307b\u3069\u66f8\u304d\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\npublic static class StoryboardExtensions\n{\n\t\/\/\/ &lt;summary&gt;\n\t\/\/\/ Storyboard \u3092\u30b3\u30d4\u30fc\u3059\u308b \n\t\/\/\/ &lt;\/summary&gt;\n\t\/\/\/ &lt;param name=&amp;quot;src&amp;quot;&gt;&lt;\/param&gt;\n\t\/\/\/ &lt;returns&gt;&lt;\/returns&gt;\n\tpublic static Storyboard Clone(this Storyboard src)\n\t{\n\t\tvar sb = new Storyboard();\n\t\tsb.AutoReverse = src.AutoReverse;\n\t\tsb.BeginTime = src.BeginTime;\n\t\tsb.Duration = src.Duration;\n\t\tsb.FillBehavior = src.FillBehavior;\n\t\tsb.RepeatBehavior = src.RepeatBehavior;\n\t\tsb.SpeedRatio = src.SpeedRatio;\n\t\tforeach (var tl in src.Children)\n\t\t{\n\t\t\tvar tld = tl.Clone();\n\t\t\tsb.Children.Add(tld);\n\t\t}\n\t\treturn sb;\n\t}\n\n\tpublic static Timeline Clone(this Timeline src)\n\t{\n\t\tTimeline dest = null;\n\t\tif (src is ColorAnimationUsingKeyFrames)\n\t\t\tdest = ((ColorAnimationUsingKeyFrames)src).Clone();\n\t\tif (src is DoubleAnimationUsingKeyFrames)\n\t\t\tdest = ((DoubleAnimationUsingKeyFrames)src).Clone();\n\t\tif (src is ObjectAnimationUsingKeyFrames)\n\t\t\tdest = ((ObjectAnimationUsingKeyFrames)src).Clone();\n\t\tif (src is PointAnimationUsingKeyFrames)\n\t\t\tdest = ((PointAnimationUsingKeyFrames)src).Clone();\n\t\tif (dest != null)\n\t\t{\n\t\t\tStoryboard.SetTargetProperty(dest, Storyboard.GetTargetProperty(src));\n\t\t\tStoryboard.SetTargetName(dest, Storyboard.GetTargetName(src));\n\t\t}\n\t\treturn dest;\n\t}\n\tpublic static ColorAnimationUsingKeyFrames Clone(this ColorAnimationUsingKeyFrames src)\n\t{\n\t\tvar dest = new ColorAnimationUsingKeyFrames();\n\t\tforeach (var kf in src.KeyFrames)\n\t\t{\n\t\t\tdest.KeyFrames.Add(kf.Clone());\n\t\t}\n\t\treturn dest;\n\t}\n\n\tpublic static ColorKeyFrame Clone(this ColorKeyFrame src)\n\t{\n\t\tColorKeyFrame dest = null;\n\t\tif (src is LinearColorKeyFrame)\n\t\t\tdest = new LinearColorKeyFrame();\n\t\tif (src is DiscreteColorKeyFrame)\n\t\t\tdest = new DiscreteColorKeyFrame();\n\t\tif (src is EasingColorKeyFrame)\n\t\t\tdest = new EasingColorKeyFrame();\n\t\tif (src is SplineColorKeyFrame)\n\t\t\tdest = new SplineColorKeyFrame();\n\t\tif (dest != null)\n\t\t{\n\t\t\tdest.KeyTime = src.KeyTime;\n\t\t\tdest.Value = src.Value;\n\t\t}\n\t\treturn dest;\n\t}\n\n\tpublic static DoubleAnimationUsingKeyFrames Clone(this DoubleAnimationUsingKeyFrames src)\n\t{\n\t\tvar dest = new DoubleAnimationUsingKeyFrames();\n\t\tforeach (var kf in src.KeyFrames)\n\t\t{\n\t\t\tdest.KeyFrames.Add(kf.Clone());\n\t\t}\n\t\treturn dest;\n\t}\n\tpublic static DoubleKeyFrame Clone(this DoubleKeyFrame src)\n\t{\n\t\tDoubleKeyFrame dest = null;\n\t\tif (src is LinearDoubleKeyFrame)\n\t\t\tdest = new LinearDoubleKeyFrame();\n\t\tif (src is DiscreteDoubleKeyFrame)\n\t\t\tdest = new DiscreteDoubleKeyFrame();\n\t\tif (src is EasingDoubleKeyFrame)\n\t\t\tdest = new EasingDoubleKeyFrame();\n\t\tif (src is SplineDoubleKeyFrame)\n\t\t\tdest = new SplineDoubleKeyFrame();\n\t\tif (dest == null)\n\t\t\treturn null;\n\n\t\tdest.KeyTime = src.KeyTime;\n\t\tdest.Value = src.Value;\n\t\treturn dest;\n\t}\n\tpublic static ObjectAnimationUsingKeyFrames Clone(this ObjectAnimationUsingKeyFrames src)\n\t{\n\t\tvar dest = new ObjectAnimationUsingKeyFrames();\n\t\tforeach (var kf in src.KeyFrames)\n\t\t{\n\t\t\tdest.KeyFrames.Add(kf.Clone());\n\t\t}\n\t\treturn dest;\n\t}\n\tpublic static ObjectKeyFrame Clone(this ObjectKeyFrame src)\n\t{\n\t\tObjectKeyFrame dest = null;\n\t\tif (src is DiscreteObjectKeyFrame)\n\t\t\tdest = new DiscreteObjectKeyFrame();\n\t\tif (dest == null)\n\t\t\treturn null;\n\n\t\tdest.KeyTime = src.KeyTime;\n\t\tdest.Value = src.Value;\n\t\treturn dest;\n\t}\n\tpublic static PointAnimationUsingKeyFrames Clone(this PointAnimationUsingKeyFrames src)\n\t{\n\t\tvar dest = new PointAnimationUsingKeyFrames();\n\t\tforeach (var kf in src.KeyFrames)\n\t\t{\n\t\t\tdest.KeyFrames.Add(kf.Clone());\n\t\t}\n\t\treturn dest;\n\t}\n\tpublic static PointKeyFrame Clone(this PointKeyFrame src)\n\t{\n\t\tPointKeyFrame dest = null;\n\t\tif (src is LinearPointKeyFrame)\n\t\t\tdest = new LinearPointKeyFrame();\n\t\tif (src is EasingPointKeyFrame)\n\t\t\tdest = new EasingPointKeyFrame();\n\t\tif (src is DiscretePointKeyFrame)\n\t\t\tdest = new DiscretePointKeyFrame();\n\t\tif (src is SplinePointKeyFrame)\n\t\t\tdest = new SplinePointKeyFrame();\n\t\tif (dest == null)\n\t\t\treturn null;\n\n\t\tdest.KeyTime = src.KeyTime;\n\t\tdest.Value = src.Value;\n\t\treturn dest;\n\t}\n}\n<\/pre>\n<p>\n\u25a0\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u306e\u958b\u59cb\u70b9\u3068\u7d42\u4e86\u70b9\u3092\u5909\u66f4\u3059\u308b\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9\u3092\u4f5c\u308b\n<\/p>\n<p>\n\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3092\u3059\u308b\u5bfe\u8c61\u3068\u3001\u958b\u59cb\u7d42\u4e86\u70b9\u3092\u6307\u5b9a\u3059\u308b\u306e\u3067\u3059\u304c\u3001\u8272\u3005\u3084\u3084\u3053\u3057\u3044\u306e\u3067\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9\u3092\u7528\u610f\u3057\u3066\u304a\u304d\u307e\u3059\u3002\u672c\u5f53\u306f\u5225\u30af\u30e9\u30b9\u306e\u307b\u3046\u304c\u3044\u3044\u3093\u3067\u3057\u3087\u3046\u304c\u3001\u9762\u5012\u306a\u306e\u3067 Storyboard \u306b\u304f\u3063\u3064\u3051\u3066\u3057\u307e\u3044\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\n\/\/\/ &lt;summary&gt;\n\/\/\/ \u5404\u7a2e\u306e\u5024\u3092\u5909\u3048\u308b\u305f\u3081\u306e\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9\n\/\/\/ &lt;\/summary&gt;\npublic static class StorybaordValueExtentions\n{\n\t\/\/\/ &lt;summary&gt;\n\t\/\/\/ \u30bf\u30fc\u30b2\u30c3\u30c8\u540d\u3092\u6307\u5b9a\u3059\u308b\n\t\/\/\/ &lt;\/summary&gt;\n\t\/\/\/ &lt;param name=&amp;quot;sb&amp;quot;&gt;&lt;\/param&gt;\n\t\/\/\/ &lt;param name=&amp;quot;name&amp;quot;&gt;&lt;\/param&gt;\n\tpublic static void SetTarget(this Storyboard sb, UIElement el)\n\t{\n\t\tforeach (var tl in sb.Children)\n\t\t{\n\t\t\tStoryboard.SetTarget(sb, el);\n\t\t}\n\t}\n\tpublic static void SetTargetName(this Storyboard sb, string name)\n\t{\n\t\tforeach (var tl in sb.Children)\n\t\t{\n\t\t\tStoryboard.SetTargetName(sb, name);\n\t\t}\n\t}\n\tpublic static void SetMovePoint(this Storyboard sb, Point start, Point end)\n\t{\n\t\t((DoubleAnimationUsingKeyFrames)sb.Children&#x5B;0]).KeyFrames&#x5B;0].Value = start.X;\n\t\t((DoubleAnimationUsingKeyFrames)sb.Children&#x5B;1]).KeyFrames&#x5B;0].Value = start.Y;\n\t\t((DoubleAnimationUsingKeyFrames)sb.Children&#x5B;0]).KeyFrames&#x5B;1].Value = end.X;\n\t\t((DoubleAnimationUsingKeyFrames)sb.Children&#x5B;1]).KeyFrames&#x5B;1].Value = end.Y;\n\t}\n}\n<\/pre>\n<p>\nstoryboard \u306f\u8907\u6570\u306e\u30bf\u30fc\u30b2\u30c3\u30c8\u3092\u540c\u6642\u306b\u52d5\u304b\u3059\u3053\u3068\u3082\u3067\u304d\u308b\u306e\u3067\u3001\u4e00\u5f8b\u3067\u5909\u3048\u3066\u3057\u307e\u3046\u306e\u306f\u56f0\u308b\u306e\u3067\u3059\u304c\u3001\u307e\u3042\u3001\u305d\u306e\u3068\u304d\u306f\u305d\u306e\u3068\u304d\u3067\u8003\u3048\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3002\n<\/p>\n<p>\n\u25a0\u5b9f\u969b\u306b\u52d5\u304b\u3057\u3066\u307f\u308b\n<\/p>\n<p>\n\u3042\u3089\u304b\u3058\u3081\u3001\u30b3\u30d4\u30fc\u5143\u306e storyboard \u3092 blend \u3067\u4f5c\u3063\u3066\u304a\u304d\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;Page.Resources&gt;\n    &lt;Storyboard x:Name=&amp;quot;sbMove&amp;quot;&gt;\n        &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=&amp;quot;(UIElement.RenderTransform).(CompositeTransform.TranslateX)&amp;quot; Storyboard.TargetName=&amp;quot;pictAni&amp;quot;&gt;\n            &lt;EasingDoubleKeyFrame x:Name=&amp;quot;sbStartX&amp;quot; KeyTime=&amp;quot;0&amp;quot; Value=&amp;quot;180.597&amp;quot;\/&gt;\n            &lt;EasingDoubleKeyFrame x:Name=&amp;quot;sbEndX&amp;quot; KeyTime=&amp;quot;0:0:1&amp;quot; Value=&amp;quot;182.09&amp;quot;\/&gt;\n        &lt;\/DoubleAnimationUsingKeyFrames&gt;\n        &lt;DoubleAnimationUsingKeyFrames Storyboard.TargetProperty=&amp;quot;(UIElement.RenderTransform).(CompositeTransform.TranslateY)&amp;quot; Storyboard.TargetName=&amp;quot;pictAni&amp;quot;&gt;\n            &lt;EasingDoubleKeyFrame x:Name=&amp;quot;sbStartY&amp;quot; KeyTime=&amp;quot;0&amp;quot; Value=&amp;quot;-152.239&amp;quot;\/&gt;\n            &lt;EasingDoubleKeyFrame x:Name=&amp;quot;sbEndY&amp;quot; KeyTime=&amp;quot;0:0:1&amp;quot; Value=&amp;quot;171.642&amp;quot;\/&gt;\n        &lt;\/DoubleAnimationUsingKeyFrames&gt;\n    &lt;\/Storyboard&gt;\n&lt;\/Page.Resources&gt;\n<\/pre>\n<p>\n\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u3059\u308b\u5bfe\u8c61\u306f\u3001\u3042\u3089\u304b\u3058\u3081\u3001Image.RenderTransform \u3068 CompositeTransform \u3092\u66f8\u3044\u3066\u304a\u304d\u307e\u3059\u3002<br \/>\n\u3053\u308c\u306f Blend \u304c\u51fa\u529b\u3059\u308b Storyboard \u306e\u7656\u306a\u306e\u3067\u3001\u624b\u4f5c\u696d\u3067\u4f5c\u308c\u3070 Margin \u3068\u304b Canvas.Left \u3042\u305f\u308a\u3092\u76f4\u63a5\u5909\u66f4\u3059\u308b\u3053\u3068\u3082\u53ef\u80fd\u3067\u3057\u3087\u3046\u3002\u4eca\u306f\u3001Blend \u3068 Visual Studio \u306e\u884c\u304d\u6765\u3092\u7c21\u5358\u306b\u3059\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3001Blend \u306e\u307b\u3046\u306b\u3042\u308f\u305b\u3066\u304a\u304d\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: xml; title: ; notranslate\" title=\"\">\n&lt;Image x:Name=&#039;pict1&#039; HorizontalAlignment=&amp;quot;Left&amp;quot; Height=&amp;quot;100&amp;quot; \n            VerticalAlignment=&amp;quot;Top&amp;quot; Width=&amp;quot;64&amp;quot; Source=&amp;quot;\/Images\/FC097-2.png&amp;quot;  Margin=&amp;quot;288,151,0,0&amp;quot;&gt;\n    &lt;Image.RenderTransform&gt;\n        &lt;CompositeTransform\/&gt;\n    &lt;\/Image.RenderTransform&gt;\n\n&lt;\/Image&gt;\n<\/pre>\n<p>\n\u81ea\u4f5c\u3057\u305f Clone \u3068\u62e1\u5f35\u30e1\u30bd\u30c3\u30c9\u3092\u4f7f\u3063\u3066\u3001pict1 \u3092\u79fb\u52d5\u3055\u305b\u307e\u3059\u3002\u3053\u3053\u3067\u306f\u3001Clone \u3057\u305f storyboard \u306f\u4f7f\u3044\u6368\u3066\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u304c\u3001\u5b9f\u969b\u306f Initialize \u6642\u306b\u30ad\u30fc\u30d7\u3057\u3066\u304a\u304d\u307e\u3059\u3002\n<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\nprivate void SbClone2Click(object sender, RoutedEventArgs e)\n{\n\tStoryboard sb = this.sbMove.Clone();\n\t\/\/ \u30bf\u30fc\u30b2\u30c3\u30c8\u3092\u5909\u3048\u308b\n\tsb.SetTarget( this.pict1 );\n\tsb.SetMovePoint(new Point(0, 0), new Point(100, 200));\n\tsb.Begin();\n}\n<\/pre>\n<p>\n\u3053\u308c\u3067\u3001storyboard \u306e XAML \u3092\u91cf\u7523\u3057\u306a\u3044\u3067\u3088\u304f\u306a\u308b\u306e\u3067\uff08\u7279\u306b\u958b\u59cb\u7d42\u4e86\u70b9\u306e\u540d\u524d\u4ed8\u3051\u3068\u304b\u304c\u9762\u5012\u306a\u306e\u3067\uff09\u3001\u82b1\u672d\u30b2\u30fc\u30e0\u306e\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u306b\u6d3b\u7528\u3067\u304d\u305d\u3046\u3002\u306a\u306e\u3067\u3001\u518d\u3073\u82b1\u672d\u30b2\u30fc\u30e0\u88fd\u4f5c\u306b\u623b\u308b\u3068\u3044\u3046\u3053\u3068\u3067\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u30a2\u30cb\u30e1\u30fc\u30b7\u30e7\u30f3\u306e\u5834\u5408\u306f\u3001 Storyboard \u306e\u5834\u5408\u306f\u3001Blend \u3067\u3061\u307e\u3061\u307e\u7de8\u96c6\u3057\u3066\u52d5\u4f5c\u78ba\u8a8d \u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30fc\u30c9\u306b\u7d44\u307f\u8fbc\u3093\u3067\u3001\u52d5\u4f5c\u78ba\u8a8d \u3082\u3046\u4e00\u5ea6\u3001Blend \u306b\u623b\u3063\u3066\u4fee\u6b63\u3002 \u307e\u305f\u307e\u305f\u3001\u30d7\u30ed\u30b0\u30e9\u30e0\u30b3\u30fc\u30c9\u306b\u7d44\u307f\u8fbc\u3093\u3067\u3001\u52d5\u4f5c &hellip; <a href=\"http:\/\/www.moonmile.net\/blog\/archives\/4087\">\u7d9a\u304d\u3092\u8aad\u3080 <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[23,52],"tags":[],"class_list":["post-4087","post","type-post","status-publish","format-standard","hentry","category-csharp","category-winrt"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4087","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/comments?post=4087"}],"version-history":[{"count":1,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4087\/revisions"}],"predecessor-version":[{"id":4088,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/posts\/4087\/revisions\/4088"}],"wp:attachment":[{"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/media?parent=4087"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/categories?post=4087"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.moonmile.net\/blog\/wp-json\/wp\/v2\/tags?post=4087"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}