DragItemThemeAnimation 类

定义

表示应用到正在拖动的项元素的预配置动画。

public ref class DragItemThemeAnimation sealed : Timeline
/// [Windows.Foundation.Metadata.Activatable(65536, "Microsoft.UI.Xaml.WinUIContract")]
/// [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 DragItemThemeAnimation final : Timeline
[Windows.Foundation.Metadata.Activatable(65536, "Microsoft.UI.Xaml.WinUIContract")]
[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 sealed class DragItemThemeAnimation : Timeline
Public NotInheritable Class DragItemThemeAnimation
Inherits Timeline
<DragItemThemeAnimation .../>
继承
Object Platform::Object IInspectable DependencyObject Timeline DragItemThemeAnimation
属性

示例

下面是启用拖动的自定义控件的示例。

// Themes/Generic.xaml
<!-- Example template of a drag-enabled custom control. The
     DragItemThemeAnimation will be run when the control
     is in the Dragging state, and reverted when it isn't.
-->
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:BlankApp1">

    <Style TargetType="local:DraggableControl" >
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:DraggableControl">
                    <Grid>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="DragStates">
                                <VisualState x:Name="NotDragging"/>
                                <VisualState x:Name="Dragging">
                                    <Storyboard>
                                        <DragItemThemeAnimation TargetName="contentRectangle"/>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Rectangle x:Name="contentRectangle" Width="100" Height="100" Fill="{TemplateBinding Background}"/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
public sealed class DraggableControl : Control
{
    public DraggableControl()
    {
        this.DefaultStyleKey = typeof(DraggableControl);
    }

    protected override void OnPointerPressed(PointerRoutedEventArgs e)
    {
        // Go to the Dragging state, which will start the DragItemThemeAnimation.
        VisualStateManager.GoToState(this, "Dragging", true);
    }

    protected override void OnPointerReleased(PointerRoutedEventArgs e)
    {
        VisualStateManager.GoToState(this, "NotDragging", true);
    }

    protected override void OnPointerMoved(PointerRoutedEventArgs e)
    {
        // dragging implementation here.
    }
}
// DraggableControl.h
struct DraggableControl : DraggableControlT<DraggableControl>
{
    DraggableControl(){ DefaultStyleKey(winrt::box_value(L"MyApp.DraggableControl")); }

    void OnPointerPressed(Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e);
    void OnPointerReleased(Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e);
    void OnPointerMoved(Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e);
};

// DraggableControl.cpp
void DraggableControl::OnPointerPressed(Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e)
{
    // Go to the Dragging state, which will start the DragItemThemeAnimation.
    Windows::UI::Xaml::VisualStateManager::GoToState(*this, L"Dragging", true);
}

void DraggableControl::OnPointerReleased(Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e)
{
    Windows::UI::Xaml::VisualStateManager::GoToState(*this, L"NotDragging", true);
}

void DraggableControl::OnPointerMoved(Windows::UI::Xaml::Input::PointerRoutedEventArgs const& e)
{
    // dragging implementation here.
}
// DraggableControl.h:
public ref class DraggableControl sealed : public Windows::UI::Xaml::Controls::Control
{
public:
    DraggableControl();
protected:
    virtual void OnPointerPressed(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
    virtual void OnPointerReleased(Windows::UI::Xaml::Input::PointerRoutedEventArgs^ e) override;
    virtual void OnPointerMoved(Windows::UI::Xaml::Input:: PointerRoutedEventArgs^ e) override;
};

// DraggableControl.cpp:
DraggableControl::DraggableControl()
{
    DefaultStyleKey = "MyApp.DraggableControl";
}

void DraggableControl::OnPointerPressed(PointerRoutedEventArgs^ e)
{
    // Go to the Dragging state, which will start the DragItemThemeAnimation
    VisualStateManager::GoToState(this, "Dragging", true);
}

void DraggableControl::OnPointerReleased(PointerRoutedEventArgs^ e)
{
    VisualStateManager::GoToState(this, "NotDragging", true);
}

void DraggableControl::OnPointerMoved(PointerRoutedEventArgs^ e)
{
    // dragging implementation here
}

注解

请注意,设置 Duration 属性不会影响此对象,因为持续时间是预配置的。

构造函数

DragItemThemeAnimation()

初始化 DragItemThemeAnimation 类的新实例。

属性

AutoReverse

获取或设置一个值,该值指示时间线在完成向前迭代后是否按相反的顺序播放。

(继承自 Timeline)
BeginTime

获取或设置此 时间线 应开始的时间。

(继承自 Timeline)
Dispatcher

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

(继承自 DependencyObject)
DispatcherQueue

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

(继承自 DependencyObject)
Duration

获取或设置此时间线播放的时间长度,而不是计数重复。

(继承自 Timeline)
FillBehavior

获取或设置一个值,该值指定动画在其活动周期结束时的行为方式。

(继承自 Timeline)
RepeatBehavior

获取或设置此时间线的重复行为。

(继承自 Timeline)
SpeedRatio

获取或设置相对于其父级的速率,此时此 时间线的进度。

(继承自 Timeline)
TargetName

获取或设置目标控件元素的引用名称。

TargetNameProperty

标识 TargetName 依赖属性。

方法

ClearValue(DependencyProperty)

清除依赖属性的本地值。

(继承自 DependencyObject)
GetAnimationBaseValue(DependencyProperty)

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

(继承自 DependencyObject)
GetValue(DependencyProperty)

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

(继承自 DependencyObject)
ReadLocalValue(DependencyProperty)

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

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

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

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

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

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

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

(继承自 DependencyObject)

事件

Completed

Storyboard 对象完成播放时发生。

(继承自 Timeline)

适用于

另请参阅