Udostępnij za pośrednictwem


AdaptiveTrigger Class

Definition

Represents a declarative rule that applies visual states based on window properties.

/// [Windows.Foundation.Metadata.ContractVersion(Microsoft.UI.Xaml.WinUIContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class AdaptiveTrigger : StateTriggerBase
[Windows.Foundation.Metadata.ContractVersion(typeof(Microsoft.UI.Xaml.WinUIContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public class AdaptiveTrigger : StateTriggerBase
Public Class AdaptiveTrigger
Inherits StateTriggerBase
Inheritance
Object IInspectable DependencyObject StateTriggerBase AdaptiveTrigger
Attributes

Examples

Tip

For more info, design guidance, and code examples, see Responsive layouts with XAML.

The following example shows how to use the StateTriggers property with an AdaptiveTrigger to create a declarative rule in XAML markup based on window size. By default, the StackPanel orientation is Vertical. When the window width is >= 720 effective pixels, the VisualState change is triggered, and the StackPanel orientation is changed to Horizontal.

<Page>
    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
        <VisualStateManager.VisualStateGroups>
            <VisualStateGroup>
                <VisualState>
                    <VisualState.StateTriggers>
                    <!--VisualState to be triggered when window width is >=720 effective pixels.-->
                        <AdaptiveTrigger MinWindowWidth="720"/>
                    </VisualState.StateTriggers>

                    <VisualState.Setters>
                        <Setter Target="myPanel.Orientation" Value="Horizontal"/>
                    </VisualState.Setters>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
        <StackPanel x:Name="myPanel" Orientation="Vertical">
            <TextBlock Text="This is a block of text. It is text block 1. " 
                       Style="{ThemeResource BodyTextBlockStyle}"/>
            <TextBlock Text="This is a block of text. It is text block 2. " 
                       Style="{ThemeResource BodyTextBlockStyle}"/>
            <TextBlock Text="This is a block of text. It is text block 3. " 
                       Style="{ThemeResource BodyTextBlockStyle}"/>
        </StackPanel>
    </Grid>
</Page>

Remarks

Use AdaptiveTriggers to create rules that automatically trigger a VisualState change when the window is a specified height or width. When you use AdaptiveTriggers in your XAML markup, you don't need to handle the Window.SizeChanged event and call VisualStateManager.GoToState in your code. Also, when you use AdaptiveTriggers in your VisualStateManager, you can see the effects of these adaptive changes directly on the XAML design surface in Microsoft Visual Studio.

You can use the MinWindowWidth and MinWindowHeight properties either independently or in conjunction with each other. This XAML shows an example of using both properties together. The trigger indicates that the corresponding VisualState is to be applied when the current window width is >= 720 effective pixels AND the current window height is >= 900 effective pixels.

<AdaptiveTrigger MinWindowWidth="720" MinWindowHeight="900"/>

Constructors

AdaptiveTrigger()

Initializes a new instance of the AdaptiveTrigger class

Properties

Dispatcher

Always returns null in a Windows App SDK app. Use DispatcherQueue instead.

(Inherited from DependencyObject)
DispatcherQueue

Gets the DispatcherQueue that this object is associated with. The DispatcherQueue represents a facility that can access the DependencyObject on the UI thread even if the code is initiated by a non-UI thread.

(Inherited from DependencyObject)
MinWindowHeight

Gets or sets the minimum window height at which the VisualState should be applied.

MinWindowHeightProperty

Identifies the MinWindowHeight dependency property.

MinWindowWidth

Gets or sets the minimum window width at which the VisualState should be applied.

MinWindowWidthProperty

Identifies the MinWindowWidth dependency property.

Methods

ClearValue(DependencyProperty)

Clears the local value of a dependency property.

(Inherited from DependencyObject)
GetAnimationBaseValue(DependencyProperty)

Returns any base value established for a dependency property, which would apply in cases where an animation is not active.

(Inherited from DependencyObject)
GetValue(DependencyProperty)

Returns the current effective value of a dependency property from a DependencyObject.

(Inherited from DependencyObject)
ReadLocalValue(DependencyProperty)

Returns the local value of a dependency property, if a local value is set.

(Inherited from DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

Registers a notification function for listening to changes to a specific DependencyProperty on this DependencyObject instance.

(Inherited from DependencyObject)
SetActive(Boolean)

Sets the value that indicates whether the state trigger is active.

(Inherited from StateTriggerBase)
SetValue(DependencyProperty, Object)

Sets the local value of a dependency property on a DependencyObject.

(Inherited from DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

Cancels a change notification that was previously registered by calling RegisterPropertyChangedCallback.

(Inherited from DependencyObject)

Applies to

See also