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

发布于 2024-09-07 18:58:17 字数 3133 浏览 4 评论 0原文

我在 xaml 中为按钮 s 编写了简单的模板。(对于 silver-light 4)
所以当我尝试使用“ControlTemplate.Triggers”时,我发现这在silver-light中是不可能的,我们必须在Silver-Light中使用Visual-State
所以我用 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>

当我使用这种样式并在此边框上移动此边框时,边框和文本块都变得不可见。所以
1)我该怎么办?
2)视觉状态有什么好的例子吗

I wrote simple template in xaml for button s.(for silver-light 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
so I wrote first ControlTemplate with Visual-State but it not work fine.(here is code)

 <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>

When i use this style and move on this border this border, both of border and textbloc became invisible. so
1) What do i do?
2) and is there any good examples for Visual-State

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青芜 2024-09-14 18:58:17

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

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)

Because of two simple mistakes u r style was not working , else all is right.

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

It will be :
Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)

2) The same goes for the textblock :
Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color}

It will be :
Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文