Hi all,
I have a problem that I can't solve concerning style, template and animation. I created this template
<UserControl.Resources>
<vsm:Style x:Key="BtnStyle" TargetType="Button">
<vsm:Setter Property="Cursor" Value="Arrow"/>
<vsm:Setter Property="Background" Value="Transparent"/>
<vsm:Setter Property="Template">
<vsm:Setter.Value>
<ControlTemplate TargetType="Button">
<Grid>
<Grid.Resources>
<SolidColorBrush x:Key="BorderBrush" Color="#FFFFFF"/>
<!-- Grid.Resources Here -->
</Grid.Resources>
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup x:Name="CommonStates">
<vsm:VisualStateGroup.Transitions>
<vsm:VisualTransition Duration="0:0:0.3" To="MouseOver"/>
</vsm:VisualStateGroup.Transitions>
<vsm:VisualState x:Name="Normal"/>
<vsm:VisualState x:Name="MouseOver">
<Storyboard x:Name="MouseOverAnimation" >
<ColorAnimation
BeginTime="00:00:00"
Duration="0"
RepeatBehavior="Forever" AutoReverse="True"
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Rectangle.Fill).(SolidColorBrush.Color)"
To="#444444" />
</Storyboard>
</vsm:VisualState>
<vsm:VisualState x:Name="Pressed"/>
<vsm:VisualState x:Name="Disabled"/>
</vsm:VisualStateGroup>
</vsm:VisualStateManager.VisualStateGroups>
<Rectangle x:Name="Background"
Fill="{TemplateBinding Background}"
RadiusX="4" RadiusY="4"/>
<Rectangle x:Name="BackgroundGradient"
Stroke="{StaticResource BorderBrush}"
StrokeThickness="1" RadiusX="4" RadiusY="4"/>
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Grid>
</ControlTemplate>
</vsm:Setter.Value>
</vsm:Setter>
</vsm:Style>
</UserControl.Resources>
When Working with only a button instance, it works.
<Button Grid.Column="0"
x:Name="btnFirst"
Style="{StaticResource BtnStyle}"
Width="30"
HorizontalAlignment="Left"
Margin="0 2 0 2">
<Image Source="../Images/Controls/btnFirst.png" Height="15" Width="15" />
</Button>
But with Two, Not
.
<Button Grid.Column="0"
x:Name="btnFirst"
Style="{StaticResource BtnStyle}"
MouseLeave="btnFirst_MouseLeave"
Width="30"
HorizontalAlignment="Left"
Margin="0 2 0 2">
<Image Source="../Images/Controls/btnFirst.png" Height="15" Width="15" />
</Button>
<Button Grid.Column="1"
x:Name="btnFastRewind"
Style="{StaticResource BtnStyle}"
MouseLeave="btnFastRewind_MouseLeave"
Width="30"
HorizontalAlignment="Left"
Margin="0 2 0 2">
<Image Source="../Images/Controls/btnFastRewind.png" Height="15" Width="15" />
</Button>
I tried to stop / restart animation on MouseLeave Event on Button, but nothing happen. Is There anyway to make that working ?
I found a part a solution there :
http://silverlight.net/forums/p/22310/79023.aspx#79023 but, if I have
100 buttons, I will need 100 ColorAnimation Element ?
Thanks.