본문 바로가기

silverlight

VisualStateManager

VisualStateManager : Control 의 상태(State) 간 전환에 사용되는 상태를 관리하는 Class

사용방법
VisualStateGroup을 VisualStateManager.VisualStateGroups 에 추가 한 뒤, VisualState를 정의하고, GoToState 함수를 사용하여 전환.
<vsm:VisualStateManager.VisualStateGroups>
<vsm:VisualStateGroup>
<vsm:VisualState x:Name="MouseEnter">
<ColorAnimation Storyboard.TargetName="rectangle" Storyboard.TargetProperty= "(Shape.Fill).(SoildColorBrush.Color)" To="Green" Duration="0:0:0"/>
<vsm:/VisualState>
</vsm:VisaulStateGroup>
</vsm:VisualStateManager.VisualStateGroups>

<Rectangle x:Name="rectangle" Width="50" Height="50" MouseEnter="rectangle_MouseEnter" Fill="Blue"/>
private void rectangle_MouseEnter(object sender, MouseEventArgs e)
{
            VisualStateManager.GoToState(this, "MouseEnter", true);
}

MouseEnter 라는 VisualState를 정의.
rectangle의 MouseEnter시 VisualStateManager.GoToState 함수를 실행 하여, rectangel의 MouseEnter State에는 rectangle의 Fill 속성을 Green으로 변경 해 준다.

VisualState : Control이 특정 상태에 있을 때 표시방식을 지정하기 위해 Name 속성에 지정된 상태가 되면 VisualState에 Control의 모양을 변경하는 Storyboard 속성을 실행하고, Control이 더 이상 해당 되는 상태에서 벗어나면 Storyboard가 중지된다.

'silverlight' 카테고리의 다른 글

Element to Element Binding  (0) 2009.06.17
Data Binding  (0) 2009.06.17
ControlTemplate 정의하기  (0) 2009.06.16
Resource에서 Style을 범용적으로 사용  (0) 2009.06.16
Style 정의하기  (0) 2009.06.16
Storyboard (Animation in Silverlight)  (0) 2009.06.15
Layout Panel #5 (WrapPanel)  (0) 2009.06.12
Layout Panel #4 (DockPanel)  (0) 2009.06.12
Layout Panel #3 (StackPanel)  (0) 2009.06.12
Layout Panel #2 (Grid)  (0) 2009.06.11