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

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

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