Share via


DisplayRotationStateTrigger Class

Definition

Trigger that activates when the device display rotation matches the specified Rotation.

public ref class DisplayRotationStateTrigger sealed : Microsoft::Maui::Controls::StateTriggerBase
public sealed class DisplayRotationStateTrigger : Microsoft.Maui.Controls.StateTriggerBase
type DisplayRotationStateTrigger = class
    inherit StateTriggerBase
Public NotInheritable Class DisplayRotationStateTrigger
Inherits StateTriggerBase
Inheritance
DisplayRotationStateTrigger

Examples

The following example shows how to use DisplayRotationStateTrigger to change the background color based on device rotation:

<ContentPage.Resources>
<Style TargetType="ContentPage">
<Setter Property="VisualStateManager.VisualStateGroups">
<VisualStateGroupList>
<VisualStateGroup>
<VisualState Name="Rotation0">
<VisualState.StateTriggers>
<controls:DisplayRotationStateTrigger Rotation="Rotation0" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Red" />
</VisualState.Setters>
</VisualState>
<VisualState Name="Rotation90">
<VisualState.StateTriggers>
<controls:DisplayRotationStateTrigger Rotation="Rotation90" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Green" />
</VisualState.Setters>
</VisualState>
<VisualState Name="Rotation180">
<VisualState.StateTriggers>
<controls:DisplayRotationStateTrigger Rotation="Rotation180" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Blue" />
</VisualState.Setters>
</VisualState>
<VisualState Name="Rotation270">
<VisualState.StateTriggers>
<controls:DisplayRotationStateTrigger Rotation="Rotation270" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Property="BackgroundColor" Value="Yellow" />
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateGroupList>
</Setter>
</Style>
</ContentPage.Resources>

Remarks

The DisplayRotationStateTrigger enables developers to create visual states that are triggered based on the device's display rotation. Unlike OrientationStateTrigger which only differentiates between portrait and landscape orientations, this trigger provides granular control over specific rotation angles (0°, 90°, 180°, 270°).

This trigger is particularly useful for applications that need to respond to specific device orientations, such as games that have different layouts for each rotation state or apps that need to handle upside-down orientations differently.

Constructors

DisplayRotationStateTrigger()

Initializes a new instance of the DisplayRotationStateTrigger class.

Fields

RotationProperty

Identifies the Rotation bindable property.

Properties

BindingContext

Gets or sets an object that contains the properties that will be targeted by the bound properties that belong to this BindableObject. This is a bindable property.

(Inherited from BindableObject)
Dispatcher

Gets the dispatcher that was available when this bindable object was created, otherwise tries to find the nearest available dispatcher (probably the window's/app's).

(Inherited from BindableObject)
IsActive (Inherited from StateTriggerBase)
IsAttached (Inherited from StateTriggerBase)
Rotation

Gets or sets the display rotation that will activate this trigger.

Methods

ApplyBindings()

Applies all the current bindings to BindingContext.

(Inherited from BindableObject)
ClearValue(BindableProperty)

Clears any value that is previously set for a bindable property.

(Inherited from BindableObject)
ClearValue(BindablePropertyKey)

Clears any value that is previously set for a bindable property, identified by its key.

(Inherited from BindableObject)
CoerceValue(BindableProperty)

Coerces the value of the specified bindable property. This is done by invoking BindableProperty.CoerceValueDelegate of the specified bindable property.

(Inherited from BindableObject)
CoerceValue(BindablePropertyKey)

Coerces the value of the specified bindable property. This is done by invoking BindableProperty.CoerceValueDelegate of the specified bindable property.

(Inherited from BindableObject)
GetValue(BindableProperty)

Returns the value that is contained in the given bindable property.

(Inherited from BindableObject)
IsSet(BindableProperty)

Determines whether or not a bindable property exists and has a value set.

(Inherited from BindableObject)
OnAttached() (Inherited from StateTriggerBase)
OnBindingContextChanged()

Raises the BindingContextChanged event.

(Inherited from BindableObject)
OnDetached() (Inherited from StateTriggerBase)
OnPropertyChanged(String)

Raises the PropertyChanged event.

(Inherited from BindableObject)
OnPropertyChanging(String)

Raises the PropertyChanging event.

(Inherited from BindableObject)
RemoveBinding(BindableProperty)

Removes a previously set binding from a bindable property.

(Inherited from BindableObject)
SetActive(Boolean) (Inherited from StateTriggerBase)
SetBinding(BindableProperty, BindingBase)

Assigns a binding to a bindable property.

(Inherited from BindableObject)
SetValue(BindableProperty, Object)

Sets the value of the specified bindable property.

(Inherited from BindableObject)
SetValue(BindablePropertyKey, Object)

Sets the value of the specified bindable property.

(Inherited from BindableObject)
UnapplyBindings()

Removes all current bindings from the current context.

(Inherited from BindableObject)

Events

BindingContextChanged

Occurs when the value of the BindingContext property changes.

(Inherited from BindableObject)
IsActiveChanged (Inherited from StateTriggerBase)
PropertyChanged

Occurs when a property value changes.

(Inherited from BindableObject)
PropertyChanging

Occurs when a property value is changing.

(Inherited from BindableObject)

Explicit Interface Implementations

IDynamicResourceHandler.SetDynamicResource(BindableProperty, String) (Inherited from BindableObject)

Extension Methods

GetPropertyIfSet<T>(BindableObject, BindableProperty, T)
SetAppTheme<T>(BindableObject, BindableProperty, T, T)
SetAppThemeColor(BindableObject, BindableProperty, Color, Color)
SetBinding(BindableObject, BindableProperty, String, BindingMode, IValueConverter, String)

Creates and applies a binding to a property.

SetBinding<TSource,TProperty>(BindableObject, BindableProperty, Func<TSource,TProperty>, BindingMode, IValueConverter, Object, String, Object, Object, Object)

Creates a binding between a property on the source object and a property on the target object.

Applies to