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 ? [:(]
I don't know if this is the problem or not, but I know there are some issues with the Color Animation working with the Visual State Manager. Maybe one of the MS guys can chime in and verify this.
If this has answered your question, please click on "Mark as Answer" on this post.
I tried your code, but I got a Javascript Error :(. I don't understand really why I got an error, and why it is not still working :(. That is strange because, if i create single control with its own style, and i use on a grid numerous instances of this
countrol, it works, but, like I am trying to do now (easier method), it does not work.
Any idea again ? I am also trying to solve this issue.
Oh! Your second method is working !!! Thanks! But, before to mark this post as resolved, would you please explain me why this is working and not what I tried to do ?
You can also keep your original Style definition, but you need to set Background in your Button xaml because you rely on the TemplateBinding for the Rectangle.Fill property which can be any kind of Brush. So you'd better initialize it with Solid color Brush.
Otherwise, the animation does not find the target.
Danuz
Member
2 Points
3 Posts
Applying the same style / template / Animation to Buttons
Aug 25, 2008 01:39 PM | LINK
Hi all,
I have a problem that I can't solve concerning style, template and animation. I created this template
When Working with only a button instance, it works.
But with Two, Not [:(].
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.
xaml bug Silverlight Storyboard Design Silverlight 2 Beta 2
pbrooks
Contributor
2715 Points
362 Posts
Re: Applying the same style / template / Animation to Buttons
Aug 25, 2008 04:25 PM | LINK
I don't know if this is the problem or not, but I know there are some issues with the Color Animation working with the Visual State Manager. Maybe one of the MS guys can chime in and verify this.
Thanks,
Page Brooks
PageBrooks.com | @pbrooks
sladapter
All-Star
43609 Points
7910 Posts
Re: Applying the same style / template / Animation to Buttons
Aug 25, 2008 04:47 PM | LINK
Try this:
<Style x:Key="BtnStyle" TargetType="Button">
<Setter Property="Cursor" Value="Arrow"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="Template">
<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 >
<ColorAnimation
BeginTime="00:00:00"
Duration="0"
RepeatBehavior="Forever" AutoReverse="True"
Storyboard.TargetName="MouseOverColor"
Storyboard.TargetProperty="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" RadiusX="4" RadiusY="4">
<Rectangle.Fill>
<SolidColorBrush x:Name="MouseOverColor" Color="White"></SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle x:Name="BackgroundGradient"
Stroke="{StaticResource BorderBrush}"
StrokeThickness="1" RadiusX="4" RadiusY="4"/>
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
OR:
<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 >
<ColorAnimation
BeginTime="00:00:00"
Duration="0"
RepeatBehavior="Forever" AutoReverse="True"
Storyboard.TargetName="Background"
Storyboard.TargetProperty="(Shape.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" RadiusX="4" RadiusY="4">
<Rectangle.Fill>
<SolidColorBrush Color="White"></SolidColorBrush>
</Rectangle.Fill>
</Rectangle>
<Rectangle x:Name="BackgroundGradient"
Stroke="{StaticResource BorderBrush}"
StrokeThickness="1" RadiusX="4" RadiusY="4"/>
<ContentPresenter
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question
Danuz
Member
2 Points
3 Posts
Re: Re: Applying the same style / template / Animation to Buttons
Aug 25, 2008 06:01 PM | LINK
HI,
I tried your code, but I got a Javascript Error :(. I don't understand really why I got an error, and why it is not still working :(. That is strange because, if i create single control with its own style, and i use on a grid numerous instances of this countrol, it works, but, like I am trying to do now (easier method), it does not work.
Any idea again ? I am also trying to solve this issue.
Danuz
Member
2 Points
3 Posts
Re: Re: Applying the same style / template / Animation to Buttons
Aug 25, 2008 06:04 PM | LINK
Oh! Your second method is working !!! Thanks! But, before to mark this post as resolved, would you please explain me why this is working and not what I tried to do ?
sladapter
All-Star
43609 Points
7910 Posts
Re: Re: Applying the same style / template / Animation to Buttons
Aug 25, 2008 06:10 PM | LINK
You can also keep your original Style definition, but you need to set Background in your Button xaml because you rely on the TemplateBinding for the Rectangle.Fill property which can be any kind of Brush. So you'd better initialize it with Solid color Brush. Otherwise, the animation does not find the target.
<Rectangle x:Name="Background"
Fill="{TemplateBinding Background}"
RadiusX="4" RadiusY="4"/>
<Button x:Name="Bnt1" Content="Test1" Background="AliceBlue" Style="{StaticResource BtnStyle}"/>
<Button x:Name="Bnt2" Content="Test2" Background="Aqua" Style="{StaticResource BtnStyle}"/>
Software Engineer
Aprimo, Inc
Please remember to mark the replies as answers if they answered your question