SilverLight中的视觉状态? (我们如何使用它)

时间:2010-06-28 04:10:29

标签: silverlight silverlight-4.0 controltemplate visualstates

我在xaml中为按钮s编写了简单的模板。(对于银光4)
So when I try use "ControlTemplate.Triggers", I found that is impossible in silver-light, and we must use Visual-State in Silver-Light
所以我用Visual-State编写了第一个ControlTemplate,但效果不好。(这里是代码)

 <Style x:Key="NextButtonStyle" TargetType="Button">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid x:Name="MainGrid">
                        <Border x:Name="MainBorder"
                                BorderThickness="2"
                                BorderBrush="#FFC0C0C0"
                                Background="Bisque"
                                CornerRadius="4 4 4 4" >
                            <TextBlock x:Name="lbl"
                                       VerticalAlignment="Center"
                                       HorizontalAlignment="Center"
                                       Text=">"
                                       Foreground="#FFC0C0C0"
                                       FontWeight="Bold"
                                       FontFamily="TimesNewRoman"
                                       FontSize="15"/>
                        </Border>
                        <vsm:VisualStateManager.VisualStateGroups>
                            <vsm:VisualStateGroup x:Name="CommonStates">
                                <vsm:VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ColorAnimationUsingKeyFrames AutoReverse="False" Duration="00:00:00.2"
                                                                      Storyboard.TargetName="MainBorder"
                                                                      Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color}">
                                            <SplineColorKeyFrame KeyTime="00:00:00" Value="#FF606060"/>
                                        </ColorAnimationUsingKeyFrames>
                                        <ColorAnimationUsingKeyFrames AutoReverse="False" Duration="00:00:00.2"
                                                                      Storyboard.TargetName="lbl"
                                                                      Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color}">
                                            <SplineColorKeyFrame KeyTime="00:00:00" Value="#FF606060"/>
                                        </ColorAnimationUsingKeyFrames>
                                    </Storyboard>
                                </vsm:VisualState>

                            </vsm:VisualStateGroup>
                        </vsm:VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

当我使用这种样式并在此边框上移动时,border和textbloc都变得不可见。所以
1)我该怎么办? 2)是否有任何关于视觉状态的好例子

1 个答案:

答案 0 :(得分:0)

由于两个简单的错误,你的风格不起作用,否则一切都是对的。

1)Storyboard.TargetProperty =“(Border.BorderBrush)。(SolidColorBrush.Color }

它将是: Storyboard.TargetProperty =“(Border.BorderBrush)。(SolidColorBrush.Color )

2)文本块也是如此: Storyboard.TargetProperty =“(TextBlock.Foreground)。(SolidColorBrush.Color }

它将是: Storyboard.TargetProperty =“(TextBlock.Foreground)。(SolidColorBrush.Color )