silverlight
VisualStateManager
Min-gu, Kim
2009. 6. 15. 18:05
VisualStateManager : Control 의 상태(State) 간 전환에 사용되는 상태를 관리하는 Class
사용방법
VisualStateGroup을 VisualStateManager.VisualStateGroups 에 추가 한 뒤, VisualState를 정의하고, GoToState 함수를 사용하여 전환.
MouseEnter 라는 VisualState를 정의.
rectangle의 MouseEnter시 VisualStateManager.GoToState 함수를 실행 하여, rectangel의 MouseEnter State에는 rectangle의 Fill 속성을 Green으로 변경 해 준다.
VisualState : Control이 특정 상태에 있을 때 표시방식을 지정하기 위해 Name 속성에 지정된 상태가 되면 VisualState에 Control의 모양을 변경하는 Storyboard 속성을 실행하고, Control이 더 이상 해당 되는 상태에서 벗어나면 Storyboard가 중지된다.
사용방법
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"/>
<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);
}
{
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가 중지된다.