Note that there are some explanatory texts on larger screens.

plurals
  1. POControlTemplate Storyboard color animation problem
    primarykey
    data
    text
    <p>I have a problem with color animation. This is my source:</p> <pre class="lang-xml prettyprint-override"><code> &lt;Window.Resources&gt; &lt;hedit:BrushToColorConverter x:Key="BrushToColorConverter" /&gt; &lt;Style x:Key="MyButtonStyle" TargetType="Button"&gt; &lt;Setter Property="OverridesDefaultStyle" Value="True"/&gt; &lt;Setter Property="Margin" Value="5"/&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="Button"&gt; &lt;ControlTemplate.Resources&gt; &lt;Storyboard x:Key="buttonAnimIn"&gt; &lt;!-- Problem line --&gt; &lt;ColorAnimation Storyboard.TargetName="bntBack" Storyboard.TargetProperty="Color" To="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType={x:Type UserControl}}, Converter={StaticResource BrushToColorConverter}}" /&gt; &lt;/Storyboard&gt; &lt;Storyboard x:Key="buttonAnimOut"&gt; &lt;ColorAnimation Storyboard.TargetName="bntBack" Storyboard.TargetProperty="Color" To="Blue" /&gt; &lt;/Storyboard&gt; &lt;Storyboard x:Key="buttonAnimForegroundIn"&gt; &lt;ColorAnimation Storyboard.TargetName="btnFore" Storyboard.TargetProperty="Color" To="Blue" /&gt; &lt;/Storyboard&gt; &lt;Storyboard x:Key="buttonAnimForegroundOut"&gt; &lt;ColorAnimation Storyboard.TargetName="btnFore" Storyboard.TargetProperty="Color" To="Red" /&gt; &lt;/Storyboard&gt; &lt;/ControlTemplate.Resources&gt; &lt;Border Name="border" BorderThickness="1" Padding="4,2" BorderBrush="DarkGray" CornerRadius="3"&gt; &lt;Border.Background&gt; &lt;SolidColorBrush Color="Blue" x:Name="bntBack" /&gt; &lt;/Border.Background&gt; &lt;ContentControl HorizontalAlignment="Center" VerticalAlignment="Center" Content="{TemplateBinding Content}"&gt; &lt;ContentControl.Foreground&gt; &lt;SolidColorBrush Color="Red" x:Name="btnFore" /&gt; &lt;/ContentControl.Foreground&gt; &lt;/ContentControl &gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;EventTrigger RoutedEvent="Button.MouseEnter"&gt; &lt;BeginStoryboard Storyboard="{StaticResource buttonAnimIn}" /&gt; &lt;BeginStoryboard Storyboard="{StaticResource buttonAnimForegroundIn}" /&gt; &lt;/EventTrigger&gt; &lt;EventTrigger RoutedEvent="Button.MouseLeave"&gt; &lt;BeginStoryboard Storyboard="{StaticResource buttonAnimOut}" /&gt; &lt;BeginStoryboard Storyboard="{StaticResource buttonAnimForegroundOut}" /&gt; &lt;/EventTrigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; &lt;/Window.Resources&gt; </code></pre> <p>The problem is:</p> <p>Cannot convert the value in attribute 'Style' to object of type 'System.Windows.Style'. Cannot freeze this Storyboard timeline tree for use across threads. Error at object 'System.Windows.Controls.Button' in markup file 'HLSLEditor;component/mainwindow.xaml' Line 223 Position 25.</p> <p>When using fixed colors it worked, but it cannot work with the Foreground color of the parent...</p> <p>How do I do an animation to the foreground or background color?</p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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