AdaptiveTrigger AdaptiveTrigger AdaptiveTrigger Class

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

Syntax

Declaration

public class AdaptiveTriggerpublic class AdaptiveTriggerPublic Class AdaptiveTrigger
<AdaptiveTrigger .../>

Inheritance Hierarchy

Remarks

Use AdaptiveTrigger s to create rules that automatically trigger a VisualState change when the window is a specified height or width. When you use AdaptiveTrigger s in your XAML markup, you don't need to handle the SizeChanged event and call GoToState(Windows.UI.Xaml.Controls.Control,System.String,System.Boolean) in your code. Also, when you use AdaptiveTrigger 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"/>

For more examples, see the XAML Responsive Techniques sample.

Examples

This 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>

Constructors summary

Initializes a new instance of the AdaptiveTrigger class

Properties summary

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

Identifies the MinWindowHeight dependency property.

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

Identifies the MinWindowWidth dependency property.

Constructors

  • AdaptiveTrigger()
    AdaptiveTrigger()
    AdaptiveTrigger()
    AdaptiveTrigger()

    Initializes a new instance of the AdaptiveTrigger class

    public AdaptiveTrigger()public AdaptiveTrigger()Public Function AdaptiveTrigger() As

Properties

  • MinWindowHeight
    MinWindowHeight
    MinWindowHeight
    MinWindowHeight

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

    public double MinWindowHeight { get; set; }public double MinWindowHeight { get; set; }Public ReadWrite Property MinWindowHeight As double
    <AdaptiveTrigger MinWindowHeight="double" .../>
    

    Property Value

    • double
      double
      double

      The minimum window height (in effective pixels) at which the VisualState should be applied.

  • MinWindowHeightProperty
    MinWindowHeightProperty
    MinWindowHeightProperty
    MinWindowHeightProperty

    Identifies the MinWindowHeight dependency property.

    public static DependencyProperty MinWindowHeightProperty { get; }public static DependencyProperty MinWindowHeightProperty { get; }Public Static ReadOnly Property MinWindowHeightProperty As DependencyProperty

    Property Value

    Remarks

    This property is only an identifier for the property system, and isn't used in most app scenarios. In most cases you set the MinWindowHeight dependency property in XAML and won't need this identifier.

    To access the MinWindowHeight dependency property in code, you can use the dependency property system, calling either GetValue(Windows.UI.Xaml.DependencyProperty) or SetValue(Windows.UI.Xaml.DependencyProperty,System.Object) and passing MinWindowHeightProperty as the dependency property identifier.

  • MinWindowWidth
    MinWindowWidth
    MinWindowWidth
    MinWindowWidth

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

    public double MinWindowWidth { get; set; }public double MinWindowWidth { get; set; }Public ReadWrite Property MinWindowWidth As double
    <AdaptiveTrigger MinWindowWidth="double" .../>
    

    Property Value

    • double
      double
      double

      The minimum window width (in effective pixels) at which the VisualState should be applied.

  • MinWindowWidthProperty
    MinWindowWidthProperty
    MinWindowWidthProperty
    MinWindowWidthProperty

    Identifies the MinWindowWidth dependency property.

    public static DependencyProperty MinWindowWidthProperty { get; }public static DependencyProperty MinWindowWidthProperty { get; }Public Static ReadOnly Property MinWindowWidthProperty As DependencyProperty

    Property Value

    Remarks

    This property is only an identifier for the property system, and isn't used in most app scenarios. In most cases you set the MinWindowWidth dependency property in XAML and won't need this identifier.

    To access the MinWindowWidth dependency property in code, you can use the dependency property system, calling either GetValue(Windows.UI.Xaml.DependencyProperty) or SetValue(Windows.UI.Xaml.DependencyProperty,System.Object) and passing MinWindowWidthProperty as the dependency property identifier.

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Attributes

Windows.Foundation.Metadata.ComposableAttribute
Windows.Foundation.Metadata.ThreadingAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.WebHostHiddenAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.StaticAttribute

Details

Assembly

Windows.UI.Xaml.dll