는 혼합을 발사이있어 :
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions"
x:Class="WpfApplication1.MainWindow"
x:Name="Window"
Title="MainWindow"
Width="640" Height="480">
<StackPanel x:Name="LayoutRoot">
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="PanelState">
<VisualState x:Name="In"/>
<VisualState x:Name="Out">
<Storyboard>
<ThicknessAnimationUsingKeyFrames Storyboard.TargetProperty="(FrameworkElement.Margin)" Storyboard.TargetName="stackPanel">
<EasingThicknessKeyFrame KeyTime="0" Value="-65,15,0,0"/>
</ThicknessAnimationUsingKeyFrames>
</Storyboard>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
<i:Interaction.Behaviors>
<ei:DataStateBehavior Binding="{Binding IsChecked, ElementName=toggleButton}" Value="True" TrueState="In" FalseState="Out"/>
</i:Interaction.Behaviors>
<Button Content="Button" Width="50" HorizontalAlignment="Left" Click="Button_Click"/>
<StackPanel x:Name="stackPanel" Height="100" HorizontalAlignment="Left" Margin="0,15,0,0">
<TextBlock><Run Text="Funnytext"/></TextBlock>
</StackPanel>
<ToggleButton x:Name="toggleButton" Content="Toggle" Width="50" HorizontalAlignment="Left"/>
</StackPanel>
</Window>
뒤에 코드 :
private void Button_Click(object sender, System.Windows.RoutedEventArgs e)
{
var sgs=VisualStateManager.GetVisualStateGroups(LayoutRoot);
var sg=sgs[0] as VisualStateGroup;
VisualStateManager.GoToElementState(LayoutRoot, ((VisualState) sg.States[sg.CurrentState == sg.States[0]?1:0]).Name,true);
}
(당신이 그렇게 의미 난 그냥이 포함 StackPanel을 알고하지 않았다) 편집 : 나쁘다, 나는 clickhandler를 포함하지 않았다는 것을 알지 못했다. 귀하의 편의를 위해 Togglebutton을 사용하여 상태를 토글하는 예제를 포함 시켰습니다 ...
또한 VisualStateGroup을 윈도우의 LayoutRoot에 추가 한 다음 'this'를 Click 이벤트에서 VSM으로 전달하려고 시도했습니다. (예 : VisualStateManager.GoToState (this, "In", true) ...하지만 그 중 하나는 나를 위해 작동하지 않습니다. –
이상한 ... 난 그냥 WinPhone7 프로젝트에 동일한 코드를 넣어, 그리고 그것은 잘 작동 .. WPF가 아닌 WinPhone7 Silverlight에서 작동하는 이유는 무엇입니까? –