Last active
October 6, 2015 11:08
-
-
Save Vanlalhriata/c1994d1260fce0cb9b6e to your computer and use it in GitHub Desktop.
Trigger XAML visual state changes from viewModels
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<Window xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | |
x:Name="window" | |
xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" | |
xmlns:ei="http://schemas.microsoft.com/expression/2010/interactions" | |
x:Class="MvvmLightExtended.MainWindow" | |
Width="800" | |
Height="600" | |
> | |
<i:Interaction.Triggers> | |
<ei:DataTrigger Binding="{Binding IsChecked, ElementName=checkBox}" Value="True"> | |
<ei:GoToStateAction StateName="VisualState1" TargetName="LayoutRoot"/> | |
</ei:DataTrigger> | |
<ei:DataTrigger Binding="{Binding IsChecked, ElementName=checkBox}" Value="False"> | |
<ei:GoToStateAction StateName="VisualState2" TargetName="LayoutRoot"/> | |
</ei:DataTrigger> | |
</i:Interaction.Triggers> | |
<!-- Use this instead for multiple states known to the viewModel --> | |
<i:Interaction.Triggers> | |
<ei:PropertyChangedTrigger Binding="{Binding VisualStateChangeTrigger}"> | |
<ei:GoToStateAction TargetObject="{Binding ElementName=_this}" StateName="{Binding TargetVisualState}"/> | |
</ei:PropertyChangedTrigger> | |
</i:Interaction.Triggers> | |
<!-- To change visual states: | |
VisualStateChangeTrigger = !VisualStateChangeTrigger; | |
--> | |
</Window> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment