1

我正在尝试使以下PointerOverVisualState 工作。理想情况下,当鼠标指针悬停在按钮上时,我想用黑色边框突出显示按钮。

我一直在尝试各种方法来完成这项工作,请帮忙。

注意:如果我设置 BorderHighlight、Border 元素的 BorderColor 值,我会得到所需的边框,但当我将它作为 VisualState 的一部分时却没有。

<Style x:Key="SecondaryButton"  TargetType="Button">
    <Setter Property="Background" Value="LightSkyBlue"></Setter>
    <Setter Property="Foreground" Value="Black"></Setter>
    <Setter Property="Padding" Value="5"></Setter>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border Height="{TemplateBinding Height}" Width="{TemplateBinding Width}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" x:Name="ButtonHighlight" BorderThickness="2" BorderBrush="Transparent">
                    <Grid>
                        <Rectangle x:Name="innerRectangle" HorizontalAlignment="Stretch" 
                                   VerticalAlignment="Stretch" Stroke="Transparent" 
                                   StrokeThickness="20" Fill="{TemplateBinding Background}" 
                                   RadiusX="15" RadiusY="15"   />

                            <ContentPresenter x:Name="Text" Content="{TemplateBinding Content}" VerticalAlignment="Center" HorizontalAlignment="Center"/>
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal">
                                        <Storyboard>
                                            <ColorAnimation From="Transparent" To="Black" Storyboard.TargetName="Text" Storyboard.TargetProperty="(Button.Foreground).(SolidColorBrush.Color)" BeginTime="0" Duration="1"></ColorAnimation>
                                            <ColorAnimation From="Transparent" To="LightSkyBlue" Storyboard.TargetName="Text" Storyboard.TargetProperty="(Button.Background).(SolidColorBrush.Color)" BeginTime="0" Duration="1"></ColorAnimation>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="PointerOver">
                                        <Storyboard>
                                            <ColorAnimation From="Transparent" To="Black" Storyboard.TargetName="ButtonHighlight" Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"  Duration="0:0:1"></ColorAnimation>
                                        </Storyboard>
                                           .
                                           .
                                           .

我剪掉了多余的代码以使问题简短明了,但这一切都可以编译,只是没有得到所需的结果。我也可以使用 2 个矩形(一个比另一个小),但想让它与实际边框一起使用。

此外,定位之间有什么区别:

   <ColorAnimation From="Transparent" To="Black" 
   Storyboard.TargetName="ButtonHighlight"   
   Storyboard.TargetProperty="BorderBrush.(SolidColorBrush.Color)"         
   Duration="0:0:1"></ColorAnimation>

   <ColorAnimation From="Transparent" To="Black" 
   Storyboard.TargetName="ButtonHighlight" 
   Storyboard.TargetProperty="(Border.BorderBrush).(SolidColorBrush.Color)"
   Duration="0:0:1"></ColorAnimation>
4

1 回答 1

-1

VisualState 称为“MouseOver”,而不是“PointerOver”

于 2013-07-18T04:20:43.480 回答