Specify the data context / class for UserControl.Resources?
Posted: 15 Dec 2014, 12:46
I have a class SBToggleButton that derives from Button. I know it's working because I have the Visibility property bound and that works. But, when I try to compile this XAML, it is looking for TapDownStoryBoard_Completed in the UserControl and not my SBToggleButton class. Here is the error:
Parsing Storyboard.Completed (@188,6).
Unable to find function 'TapDownStoryboard_Completed' on event handler 'UserControl'
Is there a way to tell the parser to look at my custom class and not the code-behind for stuff in UserControl.Resources or do I just need to subclass UserControl and put that event in the code-behind?
Note: I'm trying to port from WPF
Parsing Storyboard.Completed (@188,6).
Unable to find function 'TapDownStoryboard_Completed' on event handler 'UserControl'
Is there a way to tell the parser to look at my custom class and not the code-behind for stuff in UserControl.Resources or do I just need to subclass UserControl and put that event in the code-behind?
Code: Select all
<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d" VerticalContentAlignment="Bottom">
<UserControl.Resources>
<SBToggleButton x:Name="sbToggleButtonModel"/>
<Storyboard x:Key="TapDownStoryboard" Completed="TapDownStoryboard_Completed">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(TranslateTransform.Y)" Storyboard.TargetName="ToggleButtonTransform">
<EasingDoubleKeyFrame KeyTime="0:0:0.2" Value="36.5"/>
</DoubleAnimationUsingKeyFrames>
</Storyboard>
<ControlTemplate x:Key="SBToggleButtonTemplate">
<Grid Background="Transparent">
<!-- ... -->
</Grid>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="TapDown">
<EventTrigger.Actions>
<BeginStoryboard x:Name="TapDown" Storyboard="{StaticResource TapDownStoryboard}"/>
</EventTrigger.Actions>
</EventTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</UserControl.Resources>
<Canvas Canvas.Bottom="0" Canvas.Right="0" Background="Transparent" Height="100" Width="145" Name="SoftButtonArea" />
<SBToggleButton DataContext="{StaticResource sbToggleButtonModel}" x:Name="sbToggleButton" Grid.Column="2" VerticalAlignment="Center" HorizontalAlignment="Stretch" Height="100" Focusable="False" FocusVisualStyle="{x:Null}"
Template="{StaticResource SBToggleButtonTemplate}" Visibility="{Binding ToggleButtonVisibility}"/>
</Canvas>
</UserControl>