Collectives™ on Stack Overflow
Find centralized, trusted content and collaborate around the technologies you use most.
Learn more about Collectives
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Learn more about Teams
Ask Question
Here is some simplified XAML. On trying to run the program, I get an exception stating:
'Add value to collection of type 'System.Windows.TriggerActionCollection' threw an exception.' Line number '106' and line position '53'. ---> System.ArgumentException: The given object must be an instance of TriggerAction or a derived type.
Why is this happening?
<Grid x:Name="LoginBoxGrid" Width="400" Height="88" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.Triggers>
<Trigger Property="UIElement.IsVisible" Value="True">
<Trigger.ExitActions>
<Storyboard >
<DoubleAnimation Storyboard.TargetName="UNameBoxTranslate"
Storyboard.TargetProperty="X" From="0" To="-800" Duration="0:0:0.5"/>
<DoubleAnimation Storyboard.TargetName="UNameBoxTranslate"
Storyboard.TargetProperty="Y" From="0" To="-800" Duration="0:0:0.5"/>
</Storyboard>
</Trigger.ExitActions>
</Trigger>
</Grid.Triggers>
<TextBox >
<TextBox.RenderTransform>
<TranslateTransform x:Name="UNameBoxTranslate"/>
</TextBox.RenderTransform>
</TextBox>
</Grid>
Wrap your Storyboard in a BeginStoryboard because Storyboard is not an ExitAction but BeginStoryboard is.
<BeginStoryboard>
<Storyboard>
<!-- ... -->
</Storyboard>
</BeginStoryboard>
Edit:
Because exit actions can only be used in styles and control templates, this example would have to be reorganized a little bit. Here is one way to do that: use a ContentControl as a vanilla template and fill it will the contents above. Unfortunately now the names are now buried inside a template expansion, but that's a different question since I don't know exactly how they are intended to be used.
<ContentControl>
<ContentControl.Template>
<ControlTemplate>
<Grid x:Name="LoginBoxGrid" Width="400" Height="88" >
<Grid.ColumnDefinitions>
<ColumnDefinition Width="300"/>
<ColumnDefinition/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBox >
<TextBox.RenderTransform>
<TranslateTransform x:Name="UNameBoxTranslate"/>
</TextBox.RenderTransform>
</TextBox>
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="UIElement.IsVisible" Value="True">
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard >
<DoubleAnimation Storyboard.TargetName="UNameBoxTranslate"
Storyboard.TargetProperty="X" From="0" To="-800" Duration="0:0:0.5"/>
<DoubleAnimation Storyboard.TargetName="UNameBoxTranslate"
Storyboard.TargetProperty="Y" From="0" To="-800" Duration="0:0:0.5"/>
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</ContentControl.Template>
</ContentControl>
–
–
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.