Skip to main content

Microsoft Silverlight

Answered Question Help Please! VSM Storyboard Events not FiringRSS Feed

(0)

WJamesLord
WJamesLord

Member

Member

138 points

118 Posts

Help Please! VSM Storyboard Events not Firing

I'm trying to write my first custom control utilizing the VisualStateManager for events.  The control displays properly, but the storyboards wired via VSM do not fire.  Could someone please review this generic.xaml and tell me where I've gone wrong?

Thanks in advance for any help you can provide.

W James

<ResourceDictionary

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:ssi="clr-namespace:SSI"

xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows">

<Style TargetType="ssi:Leaf">

<Setter Property="Template">

<Setter.Value>

<ControlTemplate TargetType="ssi:Leaf">

<Canvas Width="120" Height="97" Cursor="Hand">

<vsm:VisualStateManager.VisualStateGroups>

<vsm:VisualStateGroup x:Name="CommonStates">

<vsm:VisualStateGroup.Transitions>

<vsm:VisualTransition Duration="0:0:0.2" />

</vsm:VisualStateGroup.Transitions>

<vsm:VisualState x:Name="MouseOver">

<Storyboard>

<DoubleAnimation Storyboard.TargetName="LeafText"

Storyboard.TargetProperty="(UIElement.RenderTransform).(TransformGroup.Children)[0].(RotateTransform.Angle)"

From="38" To="50" Duration="0:0:1.5" AutoReverse="True" />

</Storyboard>

</vsm:VisualState>

<vsm:VisualState x:Name="Pressed">

<Storyboard>

<DoubleAnimation Storyboard.TargetName="LeafText" Storyboard.TargetProperty="FontSize" To="18" Duration="0" />

</Storyboard>

</vsm:VisualState>

<vsm:VisualState x:Name="Disabled">

<Storyboard />

</vsm:VisualState>

<vsm:VisualState x:Name="Normal">

<Storyboard />

</vsm:VisualState>

</vsm:VisualStateGroup>

</vsm:VisualStateManager.VisualStateGroups>

<Image Source="Images/Leaf.png" />

<TextBlock x:Name="LeafText" FontFamily="Arial" FontSize="16" Width="113" TextWrapping="Wrap"

TextAlignment="Center" VerticalAlignment="Center" Text="Text">

<TextBlock.RenderTransform>

<TransformGroup>

<RotateTransform Angle="38" />

<TranslateTransform X="34" Y="0" />

</TransformGroup>

</TextBlock.RenderTransform>

</TextBlock>

</Canvas>

</ControlTemplate>

</Setter.Value>

</Setter>

</Style>

</ResourceDictionary>

 

lee_sl
lee_sl

Contributor

Contributor

2992 points

585 Posts

Re: Help Please! VSM Storyboard Events not Firing

Are you sure the right template is being applied?

----------------------------------------------
Available for consulting in Dallas, TX
http://leeontech.wordpress.com/

WJamesLord
WJamesLord

Member

Member

138 points

118 Posts

Re: Help Please! VSM Storyboard Events not Firing

It does indeed appear that the correct template is being loaded.  The control is properly rendered.  It's just that none of the events fire.  Here's a snippet of the underlying custom control class.

[TemplateVisualState(Name = "Normal", GroupName = "CommonStates")]

[TemplateVisualState(Name = "MouseOver", GroupName = "CommonStates")]

[TemplateVisualState(Name = "Pressed", GroupName = "CommonStates")]

public partial class Leaf : ContentControl

{

private TextBlock LeafText;

public static readonly DependencyProperty LeafTextProperty =

DependencyProperty.Register("Text", typeof(string), typeof(Leaf)

, new PropertyMetadata(new PropertyChangedCallback(OnTextChanged)));

private static void OnTextChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

{

Leaf leaf = (Leaf)d;leaf.SetText((string)e.NewValue);

}

public Leaf()

{

this.DefaultStyleKey = typeof(Leaf);

}

public override void OnApplyTemplate()

{

this.LeafText = (TextBlock)GetTemplateChild("LeafText");

SetText(Text);

VisualStateManager.GoToState(this, "Normal", true);

}

lee_sl
lee_sl

Contributor

Contributor

2992 points

585 Posts

Answered Question

Re: Re: Help Please! VSM Storyboard Events not Firing

you should handle the mouseevents and do something like this in the event handler

VisualStateManager.GoToState(this, "mystate', true);

----------------------------------------------
Available for consulting in Dallas, TX
http://leeontech.wordpress.com/

WJamesLord
WJamesLord

Member

Member

138 points

118 Posts

Re: Re: Re: Help Please! VSM Storyboard Events not Firing

I see.  So I still have to manually wire up the events to the VSM state.  I was under the impression that the events would auto-magically be wired.

My misunderstanding.

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities