Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF: Button ControlTemplate + Spacebar = exception?
    primarykey
    data
    text
    <p>I've thrown together a template in Expression Blend for a button, and it works alright - until I tab over to it and press the spacebar. I get the following error:</p> <p>InvalidOperationException '[Unknown]' property does not point to a DependencyObject in path '(0).(1).[0].(2)'.</p> <p>The code is as follows:</p> <pre><code> &lt;ControlTemplate x:Key="EmailButton" TargetType="{x:Type Button}"&gt; &lt;ControlTemplate.Resources&gt; &lt;Storyboard x:Key="MouseOverStoryboard"&gt; &lt;ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="border" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)"&gt; &lt;SplineColorKeyFrame KeyTime="00:00:00.4000000" Value="#FF55679E"/&gt; &lt;/ColorAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;Storyboard x:Key="UnMouseOverStoryboard"&gt; &lt;ColorAnimationUsingKeyFrames BeginTime="00:00:00" Storyboard.TargetName="border" Storyboard.TargetProperty="(Panel.Background).(GradientBrush.GradientStops)[0].(GradientStop.Color)"&gt; &lt;SplineColorKeyFrame KeyTime="00:00:00.4000000" Value="#FF92A2D3"/&gt; &lt;/ColorAnimationUsingKeyFrames&gt; &lt;/Storyboard&gt; &lt;/ControlTemplate.Resources&gt; &lt;Border x:Name="border" BorderBrush="#FF000000" BorderThickness="2,2,2,2" CornerRadius="4,4,4,4"&gt; &lt;Border.Background&gt; &lt;LinearGradientBrush EndPoint="0.47,-0.01" StartPoint="0.47,0.808"&gt; &lt;GradientStop Color="#FF92A2D3" Offset="0"/&gt; &lt;GradientStop Color="#FFFFFFFF" Offset="1"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Border.Background&gt; &lt;ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Margin="{TemplateBinding Padding}"/&gt; &lt;/Border&gt; &lt;ControlTemplate.Triggers&gt; &lt;Trigger Property="IsPressed" Value="True"&gt; &lt;Setter Property="Background" TargetName="border" Value="#FF92A2D3"/&gt; &lt;/Trigger&gt; &lt;Trigger Property="IsMouseOver" Value="True"&gt; &lt;Trigger.EnterActions&gt; &lt;BeginStoryboard x:Name="MouseOverStoryboard_BeginStoryboard" Storyboard="{StaticResource MouseOverStoryboard}"/&gt; &lt;/Trigger.EnterActions&gt; &lt;Trigger.ExitActions&gt; &lt;BeginStoryboard x:Name="UnMouseOverStoryboard_BeginStoryboard" Storyboard="{StaticResource UnMouseOverStoryboard}"/&gt; &lt;/Trigger.ExitActions&gt; &lt;/Trigger&gt; &lt;/ControlTemplate.Triggers&gt; &lt;/ControlTemplate&gt; </code></pre> <p>It would seem like either the MouseOverStoryboard or UnMouseOverStoryboard are being fired (The path mentioned in the error seems to match the TargetProperty). I'm not sure why either would fire when pressing the spacebar though... Any suggestions?</p> <p>EDIT: Thanks to Ryan Versaw, I tried the following, which now prevents spacebar-clicking from throwing the exception:</p> <pre><code> &lt;Trigger Property="IsPressed" Value="True"&gt; &lt;Setter Property="Background" TargetName="border"&gt; &lt;Setter.Value&gt; &lt;LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0"&gt; &lt;GradientStop Color="#FF92A2D3" Offset="0"/&gt; &lt;GradientStop Color="#FF92A2D3" Offset="1"/&gt; &lt;/LinearGradientBrush&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Trigger&gt; </code></pre> <p>Now the brush type stays consistent (LinearGradientBrush), and there is always 0th GradientStop available. </p> <p>I'm still curious about one other thing - what is the <i>best</i> way to go about this, considering that this sorta feels like a hack (ex: a third gradient stop is added/animated, then a third GradientStop needs to be added when IsPressed==True).</p> <p>Thanks for the suggestions! Hopefully this will help someone else, too.</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.
    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