Storyboards in ControlTemplate
Posted: 23 Jan 2019, 12:31
Hi,
I've got a bunch of controls that I want to share the same behavior (some storyboards).
My approach was to create ControlTemplate with mentioned storyboards and bind it to controls through DynamicResource like that:
but Begin() on storyboards doesn't work or I'm doing it the wrong way:
What am I doing wrong? Or there is a better way to gave a controls common behavior.
I've got a bunch of controls that I want to share the same behavior (some storyboards).
My approach was to create ControlTemplate with mentioned storyboards and bind it to controls through DynamicResource like that:
Code: Select all
<Control x:Name="CTRL" VerticalAlignment="Top" Width="80" Template="{DynamicResource behavior}" Margin="193.662,16,0,0" HorizontalAlignment="Left" >
<ControlTemplate x:Key="some behavior" TargetType="{x:Type Control}">
<ControlTemplate.Resources>
<Storyboard x:Key="Action1">
</Storyboard>
<Storyboard x:Key="Action2">
</Storyboard>
<Storyboard x:Key="Action3">
</Storyboard>
</ControlTemplate.Resources>
</ControlTemplate>
Code: Select all
ControlTemplate *pTemplate = control->GetTemplate();
if (pTemplate)
{
Storyboard *storyboard = NsStaticCast<Storyboard*>(pTemplate->GetResources()->FindName("Action1"));
if (storyboard)
{
storyboard->Begin(control);
}
}