为什么我的XAML按钮PointerOver VisualState无法正常工作?

时间:2013-07-18 02:35:10

标签: xaml windows-runtime visualstates

我正在尝试让以下PointerOver VisualState工作。理想情况下,当鼠标指针悬停在按钮上时,我想突出显示带有黑色边框的按钮。

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

注意:如果我设置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>

1 个答案:

答案 0 :(得分:-1)

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