Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p><strong>EDIT:</strong> I have overseen the fact that the <code>TextBlock</code> is in the <code>ControlTemplate</code> of your custom Window/Control. I do not think that it is possible to target a control <em>within</em> the <code>ControlTemplate</code> from a <code>Storyboard</code> <em>outside</em> of this <code>ControlTemplate</code>. You could however define a property on your custom Window which you then databind to your <code>ChangeOccurred</code> property, and then add the trigger to your <code>ControlTemplate</code> which will now get triggered by the custom Control's property rather than the Window's ViewModel's property (of course, indirectly it is triggered by the ViewModel because <code>ChangeOccurred</code> is bound to the property of the custom Window which in turn triggers the animation - uh, complex sentence, hope you understand). Is this an option? Could you follow? ;-)</p> <p>Maybe some code helps:</p> <pre><code>public class MyCustomWindow : Window { public static readonly DependencyProperty ChangeOccurred2 = DependencyProperty.Register(...); public bool ChangeOccurred2 { ... } // ... } </code></pre> <p>And some XAML:</p> <pre><code>&lt;local:MyCustomWindow ChangeOccurred2="{Binding ChangeOccurred}" ... &gt; &lt;!-- Your content here... --&gt; &lt;/local:MyCustomWindow&gt; &lt;!-- Somewhere else (whereever your ControlTemplate is defined) --&gt; &lt;ControlTemplate TargetType="{x:Type local:MyCustomWindow}"&gt; &lt;!-- your template here --&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="ChangeOccurred2" Value="True"&gt; &lt;Trigger.EnterActions&gt; &lt;BeginStoryboard&gt; &lt;Storyboard BeginTime="00:00:00" Duration="0:0:2" Storyboard.TargetName="txtWhatever" Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"&gt; &lt;ColorAnimation FillBehavior="Stop" From="Black" To="Red" Duration="0:0:0.5" AutoReverse="True"/&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/Trigger.EnterActions&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; </code></pre> <p><strong>Note:</strong> I named the Window's property <code>ChangeOccurred2</code> because I wanted it to be distinguishable from the ViewModel's <code>ChangeOccurred</code> property. Of course, you should choose a better name for this property. However, I am missing the background for such a decision.</p> <hr> <p><strong>My old answer:</strong></p> <p>So, you want to animate a <code>TextBlock</code> which is in the content of a (custom) Window?!</p> <p>Why do you want to set the style on the Window, and not on the <code>TextBlock</code> itself? Maybe you should try something like this (did not test this!):</p> <pre><code>&lt;local:MyCustomWindow ... &gt; &lt;!-- ... --&gt; &lt;TextBlock x:Name="textBlockAnimated" ... &gt; &lt;TextBlock.Style&gt; &lt;Style TargetType="{x:Type TextBlock}"&gt; &lt;Style.Triggers&gt; &lt;DataTrigger Binding="{Binding ChangeOccurred}" Value="True"&gt; &lt;DataTrigger.EnterActions&gt; &lt;BeginStoryboard&gt; &lt;Storyboard BeginTime="00:00:00" Duration="0:0:2" Storyboard.TargetProperty="(Background).(SolidColorBrush.Color)"&gt; &lt;ColorAnimation FillBehavior="Stop" From="Black" To="Red" Duration="0:0:0.5" AutoReverse="True"/&gt; &lt;/Storyboard&gt; &lt;/BeginStoryboard&gt; &lt;/DataTrigger.EnterActions&gt; &lt;/DataTrigger&gt; &lt;/Style.Triggers&gt; &lt;/Style&gt; &lt;/TextBlock.Style&gt; &lt;/TextBlock&gt; &lt;!-- ... --&gt; &lt;/local:MyCustomWindow&gt; </code></pre> <p>The <code>{Binding ChangeOccurred}</code> might not be sufficient. You might have to add a <code>DataContext</code> to the <code>TextBlock</code>, or add a <code>RelativeSource</code> or something.</p>
 

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