Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>A question about <code>Storyboard</code> with no xaml method doesn't look too nice.</p> <p>So here's an alternative to doing the same as your posted answer from xaml:</p> <p>Firstly create the <code>Storyboard</code> in xaml Resources and assign a <code>Key</code></p> <pre><code>&lt;Storyboard x:Key="MyStoryboard"&gt; &lt;ColorAnimation BeginTime="0:0:0" Duration="0:0:2" Storyboard.TargetProperty="(Label.Foreground).(SolidColorBrush.Color)" To="Yellow" /&gt; &lt;ColorAnimation BeginTime="0:0:2" Duration="0:0:3" Storyboard.TargetProperty="(Label.Foreground).(SolidColorBrush.Color)" To="Transparent" /&gt; &lt;/Storyboard&gt; </code></pre> <p>Next since you want to invoke this from code behind on dynamic <code>Label</code> you can do something like this in your code-behind to invoke it on this dynamically added <code>Label</code>:</p> <pre><code>var myStoryboard = (Storyboard)TryFindResource("MyStoryboard"); foreach(var animation in myStoryboard.Children) Storyboard.SetTarget(animation, /* WhateverDynamicLabelControl */); myStoryboard.Begin(); </code></pre> <p>You can get working-demo of this from <a href="https://www.dropbox.com/s/tbfxebjonza34ru/WpfApplication27.rar" rel="nofollow">here</a>. If you can avoid the code-behind to invoke the <code>Storyboard</code>, then do go for that but I'm not sure how your View is setup for that</p> <p><strong>Update:</strong></p> <p>To access the same <code>Storyboard</code> from multiple views, either </p> <ul> <li>move the <code>Storyboard</code> to a higher resource scope that can be reached by both views(such as in app.xaml)</li> <li>Put the <code>Storyboard</code> in a <code>ResourceDictionary</code> and merge this dictionary into the views you need the Storyboard in.</li> </ul> <p>For either of these approaches make sure you specify <code>x:Shared="False"</code> on your <code>Storyboard</code> to prevent the read-only modification error.</p> <p>so instead of </p> <pre><code>&lt;Storyboard x:Key="MyStoryboard"&gt; </code></pre> <p>you will have</p> <pre><code>&lt;Storyboard x:Key="MyStoryboard" x:Shared="False"&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload