title | author | description | keywords |
---|---|---|---|
State Triggers |
dotMorten |
A collection of custom visual State Triggers |
windows 10, uwp, windows community toolkit, uwp community toolkit, uwp toolkit, CompareStateTrigger, ControlSizeTrigger, FullScreenModeStateTrigger, IsEqualStateTrigger, IsNotEqualStateTrigger, IsNullOrEmptyStateTriggers, NetworkConnectionStateTrigger, RegexStateTrigger, UserHandPreferenceStateTrigger, UserInteractionModeStateTrigger |
A collection of custom visual State Triggers.
Trigger | Purpose |
---|---|
CompareStateTrigger | Enables a state if the value is equal to, greater than, or less than another value |
ControlSizeTrigger | Enables a state if the target control meets the specified size |
FullScreenModeStateTrigger | Trigger for switching when in full screen mode |
IsEqualStateTrigger | Enables a state if the value is equal to another value |
IsNotEqualStateTrigger | Enables a state if the value is not equal to another value |
IsNullOrEmptyStateTrigger | Enables a state if an Object is null or a String/IEnumerable is empty |
NetworkConnectionStateTrigger | Trigger for switching when the network availability changes |
RegexStateTrigger | Enables a state if the regex expression is true for a given string value |
UserHandPreferenceStateTrigger | Trigger for switching UI based on whether the user favors their left or right hand |
UserInteractionModeStateTrigger | Trigger for switching when the User interaction mode changes (tablet mode) |
<VisualState.StateTriggers>
<triggers:CompareStateTrigger Value="{Binding Value,ElementName=Slider, Mode=OneWay}" Comparison="LessThanOrEqual" To="3"/>
</VisualState.StateTriggers>
<VisualState.StateTriggers>
<triggers:ControlSizeTrigger TargetElement="{x:Bind ParentGrid}" MinWidth="400" MaxWidth="500" MinHeight="50" MaxHeight="100"/>
</VisualState.StateTriggers>
<VisualState.StateTriggers>
<triggers:FullScreenModeStateTrigger IsFullScreen="true" />
</VisualState.StateTriggers>
<VisualState.StateTriggers>
<triggers:IsEqualStateTrigger Value="{Binding IsChecked, ElementName=checkbox, Mode=OneWay}" To="{x:Null}" />
</VisualState.StateTriggers>
<VisualState.StateTriggers>
<triggers:IsNotEqualStateTrigger Value="{Binding IsChecked, ElementName=checkbox, Mode=OneWay}" To="{x:Null}" />
</VisualState.StateTriggers>
<VisualState.StateTriggers>
<triggers:IsNullOrEmptyStateTrigger Value="{Binding Text, ElementName=OurTextBox, Mode=OneWay}"/>
</VisualState.StateTriggers>
<VisualState.StateTriggers>
<triggers:NetworkConnectionStateTrigger ConnectionState="Connected" />
</VisualState.StateTriggers>
<VisualState.StateTriggers>
<triggers:RegexStateTrigger Value="{Binding Text, ElementName=emailTextBox, Mode=OneWay}"
Expression="^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$"
Options="IgnoreCase" />
</VisualState.StateTriggers>
<VisualState.StateTriggers>
<triggers:UserHandPreferenceStateTrigger HandPreference="LeftHanded" />
</VisualState.StateTriggers>
<VisualState.StateTriggers>
<triggers:UserInteractionModeStateTrigger InteractionMode="Mouse" />
</VisualState.StateTriggers>
Triggers sample page Source. You can see this in action in the Windows Community Toolkit Sample App.
Device family | Universal, 10.0.16299.0 or higher |
---|---|
Namespace | Microsoft.Toolkit.Uwp.UI.Triggers |
NuGet package | Microsoft.Toolkit.Uwp.UI |