日期:2014-05-17  浏览次数:20830 次

WPF,控件的可视状态,看下这段代码

<Grid>
    <Rectangle Name="Rectangle1" MouseEnter="ColorChangeMouseEvent" Margin="198,17,0,0" Height="88" 
VerticalAlignment="Top" HorizontalAlignment="Left" Width="100">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup Name="MouseStates">
                    <VisualState Name="BlueState" />
                <VisualStateGroup.Transitions>
                        <VisualTransition To="BlueState" GeneratedDuration="0:0:2">
                            <VisualTransition.Storyboard>
                                <Storyboard>
                                    <ColorAnimation To="Blue" Storyboard.TargetName="rectBrush" Storyboard.TargetProperty="Color"/>
                                </Storyboard>
                            </VisualTransition.Storyboard>
                        </VisualTransition>                       
                    </VisualStateGroup.Transitions>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <Rectangle.Fill>
            <SolidColorBrush x:Name="rectBrush" Color="Orange"/>