Share via


AdaptiveTrigger 类

定义

表示基于窗口属性应用视觉状态的声明性规则。

/// [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
继承
Object IInspectable DependencyObject StateTriggerBase AdaptiveTrigger
属性

示例

提示

有关详细信息、设计指南和代码示例,请参阅 使用 XAML 的响应式布局

以下示例演示如何将 StateTriggers 属性与 一起使用 AdaptiveTrigger ,以基于窗口大小在 XAML 标记中创建声明性规则。 默认情况下, StackPanel 方向为 Vertical。 当窗口宽度 >= 720 有效像素时,将触发 VisualState 更改,并将 StackPanel 方向更改为 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>

注解

使用 AdaptiveTriggers 创建规则,在窗口为指定高度或宽度时自动触发 VisualState 更改。 在 XAML 标记中使用 AdaptiveTriggers 时,无需处理 Window.SizeChanged 事件并在代码中调用 VisualStateManager.GoToState 。 此外,在 VisualStateManager 中使用 AdaptiveTriggers 时,可以直接在 Microsoft Visual Studio 的 XAML 设计图面上查看这些自适应更改的效果。

可以独立或结合使用 MinWindowWidthMinWindowHeight 属性。 此 XAML 演示了同时使用这两个属性的示例。 触发器指示当当前窗口宽度 >= 720 有效像素且当前窗口高度>为 = 900 有效像素时,将应用相应的 VisualState

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

构造函数

AdaptiveTrigger()

初始化 AdaptiveTrigger 类的新实例

属性

Dispatcher

始终在Windows 应用 SDK应用中返回 null 。 请改用 DispatcherQueue

(继承自 DependencyObject)
DispatcherQueue

DispatcherQueue获取与此对象关联的 。 表示 DispatcherQueue 一个可以在 UI 线程上访问 DependencyObject 的设施,即使代码是由非 UI 线程启动的。

(继承自 DependencyObject)
MinWindowHeight

获取或设置应应用 VisualState 的最小窗口高度。

MinWindowHeightProperty

标识 MinWindowHeight 依赖属性。

MinWindowWidth

获取或设置应应用 VisualState 的最小窗口宽度。

MinWindowWidthProperty

标识 MinWindowWidth 依赖属性。

方法

ClearValue(DependencyProperty)

清除依赖属性的本地值。

(继承自 DependencyObject)
GetAnimationBaseValue(DependencyProperty)

返回为依赖属性建立的任何基值,该基值适用于动画未处于活动状态的情况。

(继承自 DependencyObject)
GetValue(DependencyProperty)

DependencyObject 返回依赖属性的当前有效值。

(继承自 DependencyObject)
ReadLocalValue(DependencyProperty)

如果设置了本地值,则返回依赖属性的本地值。

(继承自 DependencyObject)
RegisterPropertyChangedCallback(DependencyProperty, DependencyPropertyChangedCallback)

注册通知函数,用于侦听此 DependencyObject 实例上对特定 DependencyProperty 的更改。

(继承自 DependencyObject)
SetActive(Boolean)

设置指示状态触发器是否处于活动状态的值。

(继承自 StateTriggerBase)
SetValue(DependencyProperty, Object)

设置 DependencyObject 上依赖属性的本地值。

(继承自 DependencyObject)
UnregisterPropertyChangedCallback(DependencyProperty, Int64)

取消以前通过调用 RegisterPropertyChangedCallback 注册的更改通知。

(继承自 DependencyObject)

适用于

另请参阅